Skip to content

Commit

Permalink
add some unit testing with a new workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Dec 2, 2023
1 parent dd1f9c8 commit 28bea6b
Show file tree
Hide file tree
Showing 4 changed files with 10,072 additions and 489 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Unit Test
on:
push:
branches-ignore:
- main
pull_request:
- main
workflow_call:

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get go version from go.mod
run: |
echo "GO_VERSION=$(grep '^go ' go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Install dependencies
run: |
go install github.com/golang/mock/[email protected]
- name: Generate Mocks
run: |
make mocks
- name: Test with go
run: |
make coverage
# - name: Upload unit coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# token: ${{secrets.CODECOV_TOKEN}}
# flags: unit
# files: coverage.cov
# verbose: false
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ mocks: $(MOCKGEN)
$(MOCKGEN) --source info/as_parser.go --destination info/as_parser_mock.go --package info
$(MOCKGEN) --source asconfig/generate.go --destination asconfig/generate_mock.go --package asconfig

.PHONY: test
test: mocks
go test -v ./...

.PHONY: coverage
coverage:
go test ./... -coverprofile coverage.cov -coverpkg ./...
grep -v "_mock.go" coverage.cov > coverage_no_mocks.cov
mv coverage_no_mocks.cov coverage.cov
go tool cover -func coverage.cov

.PHONY: clean-mocks
clean-mocks:
rm info/as_parser_mock.go
rm asconfig/generate_mock.go
rm asconfig/generate_mock.go

.PHONY: clean
clean: clean-mocks
rm coverage.cov
294 changes: 291 additions & 3 deletions asconfig/asconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func (suite *AsConfigTestSuite) TestAsConfigGetFlatMap() {
},
},
&Conf{
"namespaces.{test}.index": 0,
"namespaces.{test}.<index>": 0,
"namespaces.{test}.name": "test",
"namespaces.{test}.storage-engine.type": "memory",
"namespaces.{bar}.index": 1,
"namespaces.{bar}.<index>": 1,
"namespaces.{bar}.name": "bar",
"namespaces.{bar}.storage-engine.type": "memory",
},
Expand All @@ -69,7 +69,7 @@ func (suite *AsConfigTestSuite) TestAsConfigGetFlatMap() {
},
},
&Conf{
"xdr.datacenters.{DC1}.index": 0,
"xdr.datacenters.{DC1}.<index>": 0,
"xdr.datacenters.{DC1}.name": "DC1",
"xdr.datacenters.{DC1}.dc-node-address-port": []string{"1.1.1.1:3000"},
"xdr.datacenters.{DC1}.dc-int-ext-ipmap": []string{"1.1.1.1 2.2.2.2", "3.3.3.3 4.4.4.4"},
Expand All @@ -92,6 +92,294 @@ func (suite *AsConfigTestSuite) TestAsConfigGetFlatMap() {
}
}

func (suite *AsConfigTestSuite) TestAsConfigGetExpandMap() {
testCases := []struct {
name string
version string
inputMap map[string]interface{}
expected Conf
}{
{
"namespace context",
"7.0.0",
map[string]interface{}{
"logging": []Conf{
{
"name": "/var/log/aerospike/aerospike.log",
"aggr": "INFO",
"alloc": "INFO",
"appeal": "INFO",
"arenax": "INFO",
"as": "INFO",
"audit": "INFO",
"batch": "INFO",
"batch-sub": "INFO",
"bin": "INFO",
"clustering": "INFO",
"config": "INFO",
"drv_pmem": "INFO",
"drv_ssd": "INFO",
"exchange": "INFO",
"exp": "INFO",
"fabric": "INFO",
"flat": "INFO",
"geo": "INFO",
"hardware": "INFO",
"hb": "INFO",
"health": "INFO",
"hlc": "INFO",
"index": "INFO",
"info": "INFO",
"info-port": "INFO",
"key-busy": "INFO",
"migrate": "INFO",
"misc": "INFO",
"msg": "INFO",
"namespace": "INFO",
"nsup": "INFO",
"os": "INFO",
"particle": "INFO",
"partition": "INFO",
"proto": "INFO",
"proxy": "INFO",
"proxy-divert": "INFO",
"query": "INFO",
"record": "INFO",
"roster": "INFO",
"rw": "INFO",
"rw-client": "INFO",
"secrets": "INFO",
"security": "INFO",
"service": "INFO",
"service-list": "INFO",
"sindex": "INFO",
"skew": "INFO",
"smd": "INFO",
"socket": "INFO",
"storage": "INFO",
"tls": "INFO",
"truncate": "INFO",
"tsvc": "INFO",
"udf": "INFO",
"vault": "INFO",
"vmapx": "INFO",
"xdr": "INFO",
"xdr-client": "INFO",
"xmem": "INFO",
},
{
"name": "console",
"aggr": "INFO",
"alloc": "INFO",
"appeal": "INFO",
"arenax": "INFO",
"as": "INFO",
"audit": "INFO",
"batch": "INFO",
"batch-sub": "INFO",
"bin": "INFO",
"clustering": "INFO",
"config": "INFO",
"drv_pmem": "INFO",
"drv_ssd": "INFO",
"exchange": "INFO",
"exp": "INFO",
"fabric": "INFO",
"flat": "INFO",
"geo": "INFO",
"hardware": "INFO",
"hb": "INFO",
"health": "INFO",
"hlc": "INFO",
"index": "INFO",
"info": "INFO",
"info-port": "INFO",
"key-busy": "INFO",
"migrate": "INFO",
"misc": "INFO",
"msg": "INFO",
"namespace": "INFO",
"nsup": "INFO",
"os": "INFO",
"particle": "INFO",
"partition": "INFO",
"proto": "INFO",
"proxy": "INFO",
"proxy-divert": "INFO",
"query": "INFO",
"record": "INFO",
"roster": "INFO",
"rw": "INFO",
"rw-client": "INFO",
"secrets": "INFO",
"security": "INFO",
"service": "INFO",
"service-list": "INFO",
"sindex": "INFO",
"skew": "INFO",
"smd": "INFO",
"socket": "INFO",
"storage": "INFO",
"tls": "INFO",
"truncate": "INFO",
"tsvc": "INFO",
"udf": "INFO",
"vault": "INFO",
"vmapx": "INFO",
"xdr": "INFO",
"xdr-client": "INFO",
"xmem": "INFO",
},
},
},
Conf{
"logging": []Conf{
{
"name": "/var/log/aerospike/aerospike.log",
"aggr": "INFO",
"alloc": "INFO",
"appeal": "INFO",
"arenax": "INFO",
"as": "INFO",
"audit": "INFO",
"batch": "INFO",
"batch-sub": "INFO",
"bin": "INFO",
"clustering": "INFO",
"config": "INFO",
"drv_pmem": "INFO",
"drv_ssd": "INFO",
"exchange": "INFO",
"exp": "INFO",
"fabric": "INFO",
"flat": "INFO",
"geo": "INFO",
"hardware": "INFO",
"hb": "INFO",
"health": "INFO",
"hlc": "INFO",
"index": "INFO",
"info": "INFO",
"info-port": "INFO",
"key-busy": "INFO",
"migrate": "INFO",
"misc": "INFO",
"msg": "INFO",
"namespace": "INFO",
"nsup": "INFO",
"os": "INFO",
"particle": "INFO",
"partition": "INFO",
"proto": "INFO",
"proxy": "INFO",
"proxy-divert": "INFO",
"query": "INFO",
"record": "INFO",
"roster": "INFO",
"rw": "INFO",
"rw-client": "INFO",
"secrets": "INFO",
"security": "INFO",
"service": "INFO",
"service-list": "INFO",
"sindex": "INFO",
"skew": "INFO",
"smd": "INFO",
"socket": "INFO",
"storage": "INFO",
"tls": "INFO",
"truncate": "INFO",
"tsvc": "INFO",
"udf": "INFO",
"vault": "INFO",
"vmapx": "INFO",
"xdr": "INFO",
"xdr-client": "INFO",
"xmem": "INFO",
},
{
"name": "console",
"aggr": "INFO",
"alloc": "INFO",
"appeal": "INFO",
"arenax": "INFO",
"as": "INFO",
"audit": "INFO",
"batch": "INFO",
"batch-sub": "INFO",
"bin": "INFO",
"clustering": "INFO",
"config": "INFO",
"drv_pmem": "INFO",
"drv_ssd": "INFO",
"exchange": "INFO",
"exp": "INFO",
"fabric": "INFO",
"flat": "INFO",
"geo": "INFO",
"hardware": "INFO",
"hb": "INFO",
"health": "INFO",
"hlc": "INFO",
"index": "INFO",
"info": "INFO",
"info-port": "INFO",
"key-busy": "INFO",
"migrate": "INFO",
"misc": "INFO",
"msg": "INFO",
"namespace": "INFO",
"nsup": "INFO",
"os": "INFO",
"particle": "INFO",
"partition": "INFO",
"proto": "INFO",
"proxy": "INFO",
"proxy-divert": "INFO",
"query": "INFO",
"record": "INFO",
"roster": "INFO",
"rw": "INFO",
"rw-client": "INFO",
"secrets": "INFO",
"security": "INFO",
"service": "INFO",
"service-list": "INFO",
"sindex": "INFO",
"skew": "INFO",
"smd": "INFO",
"socket": "INFO",
"storage": "INFO",
"tls": "INFO",
"truncate": "INFO",
"tsvc": "INFO",
"udf": "INFO",
"vault": "INFO",
"vmapx": "INFO",
"xdr": "INFO",
"xdr-client": "INFO",
"xmem": "INFO",
},
},
},
},
}

Init(logr.Discard(), "/Users/jesseschmidt/Developer/aerospike-admin/lib/live_cluster/client/config-schemas") // TODO: replace with better location. Maybe a single test schema

for _, tc := range testCases {
suite.Run(tc.name, func() {
logger := logr.Discard()

asConfig, err := NewMapAsConfig(logger, tc.version, tc.inputMap)
actual := asConfig.ToMap()

suite.Assert().Nil(err)
suite.Assert().Equal(tc.expected, *actual)
})
}
}

func TestAsConfigTestSuiteSuite(t *testing.T) {
suite.Run(t, new(AsConfigTestSuite))
}
Loading

0 comments on commit 28bea6b

Please sign in to comment.