Unit Tested Indexers Package with a 83% overall coverage. Individual coverages are as below.
factory.go: 100%
local.go: 100%
elastic.go: 78.7%
opensearch.go: 76.6%
Testing
Test cases for each .go file can be found in the .go. Each test case covers some part of the code. An example test case is shown below:
Along with this example case, many other test cases were included to cover the code. In order to test the .go files the following commands can be followed by the reviewers. Commands to obtain the coverage report is also included.
cd indexers
go get golang.org/x/tools/cmd/cover
go get github.com/onsi/ginkgo/v2
go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo@latest
ginkgo -v -cover --coverprofile cover.out
go tool cover -html=cover.out
Test suite run output
[sboyapal@sboyapal indexers]$ ginkgo -v -cover --coverprofile cover.out
Running Suite: Indexers Suite - /home/sboyapal/Documents/forkedCommons/go-commons/indexers
==========================================================================================
Random Seed: 1687959489
Will run 22 of 22 specs
------------------------------
[BeforeSuite]
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/test_assets_test.go:10
[BeforeSuite] PASSED [0.000 seconds]
------------------------------
Tests for local.go Default behavior of local.go, new() returns err no metrics directory
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/local_test.go:29
• [0.000 seconds]
------------------------------
Tests for local.go Default behavior of local.go, new() returns nil as error
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/local_test.go:34
• [0.000 seconds]
------------------------------
Tests for local.go Default behaviour of local.go, Index() No err is returned
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/local_test.go:70
• [0.000 seconds]
------------------------------
Tests for local.go Default behaviour of local.go, Index() No err is returned
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/local_test.go:76
• [0.000 seconds]
------------------------------
Tests for local.go Default behaviour of local.go, Index() Err is returned metricsdirectory has fault
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/local_test.go:83
• [0.000 seconds]
------------------------------
Tests for local.go Default behaviour of local.go, Index() Err is returned by documents not processed
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/local_test.go:91
• [0.000 seconds]
------------------------------
Factory.go Unit Tests: NewIndexer() Default behaviour of NewIndexer() returns indexer and nil
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/factory_test.go:30
• [0.001 seconds]
------------------------------
Factory.go Unit Tests: NewIndexer() Default behaviour of NewIndexer() returns indexer and err status bad gateway
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/factory_test.go:37
• [0.000 seconds]
------------------------------
Factory.go Unit Tests: NewIndexer() Default behaviour of NewIndexer() returns indexer and err unknown indexer
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/factory_test.go:48
• [0.000 seconds]
------------------------------
Tests for opensearch.go Tests for new() Returns error
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/opensearch_test.go:32
• [0.000 seconds]
------------------------------
Tests for opensearch.go Tests for new() when no url is passed
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/opensearch_test.go:42
• [0.007 seconds]
------------------------------
Tests for opensearch.go Tests for new() Returns err not a valid URL in env variable
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/opensearch_test.go:50
• [0.000 seconds]
------------------------------
Tests for opensearch.go Tests for new() Returns err no index name
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/opensearch_test.go:59
• [0.000 seconds]
------------------------------
Tests for opensearch.go Tests for Index() No err returned
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/opensearch_test.go:98
• [0.044 seconds]
------------------------------
Tests for opensearch.go Tests for Index() err returned docs not processed
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/opensearch_test.go:103
• [0.001 seconds]
------------------------------
Factory.go Unit Tests: NewIndexer() Default behaviour of NewIndexer() returns indexer and nil
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/factory_test.go:77
• [0.001 seconds]
------------------------------
Tests for elastic.go Tests for new() Returns error status bad request
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/elastic_test.go:33
• [0.000 seconds]
------------------------------
Tests for elastic.go Tests for new() when no url is passed
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/elastic_test.go:43
• [0.006 seconds]
------------------------------
Tests for elastic.go Tests for new() Returns err not passing a valid URL in env variable
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/elastic_test.go:52
• [0.000 seconds]
------------------------------
Tests for elastic.go Tests for new() Returns err no index name
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/elastic_test.go:61
• [0.000 seconds]
------------------------------
Tests for elastic.go Tests for Index() No err returned
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/elastic_test.go:101
• [0.041 seconds]
------------------------------
Tests for elastic.go Tests for Index() err returned docs not processed
/home/sboyapal/Documents/forkedCommons/go-commons/indexers/elastic_test.go:106
• [0.001 seconds]
------------------------------
Ran 22 of 22 Specs in 0.104 seconds
SUCCESS! -- 22 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS
github.com/cloud-bulldozer/go-commons/indexers coverage: 82.8% of statements
composite coverage: 82.8% of statements
Ginkgo ran 1 suite in 624.890917ms
Test Suite Passed
Description
Unit Tested Indexers Package with a 83% overall coverage. Individual coverages are as below. factory.go: 100% local.go: 100% elastic.go: 78.7% opensearch.go: 76.6%
Testing
Test cases for each.go file can be found in the .go. Each test case covers some part of the code. An example test case is shown below:
Along with this example case, many other test cases were included to cover the code. In order to test the .go files the following commands can be followed by the reviewers. Commands to obtain the coverage report is also included.
Test suite run output