Skip to content

Commit

Permalink
refactor tests to Init schemas from environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Dec 6, 2023
1 parent ac06c31 commit 644aab9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7,517 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/unittest.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Test
name: Tests
on:
push:
branches-ignore:
Expand All @@ -21,18 +21,20 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- name: Install dependencies
run: |
echo "CWD=$(pwd)" >> $GITHUB_ENV
go install github.com/golang/mock/[email protected]
git clone https://github.com/aerospike/schemas.git
- name: Generate Mocks
run: |
make mocks
- name: Test with go
env:
TEST_SCHEMA_DIR: ${{ env.CWD }}/schemas/json/aerospike
run: |
make coverage
# Uncomment the following lines when codecov secret is uploaded
- name: Upload unit coverage to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
flags: unit
files: coverage.cov
verbose: false
28 changes: 15 additions & 13 deletions asconfig/generate_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package asconfig

import (
"log"
"os"
"testing"

aero "github.com/aerospike/aerospike-client-go/v6"
Expand All @@ -20,6 +22,14 @@ func (suite *GenerateE2eTestSuite) SetupSuite() {
if err != nil {
suite.T().Fatal(err)
}

schemaDir := os.Getenv("TEST_SCHEMA_DIR")
if schemaDir == "" {
log.Printf("Env var TEST_SCHEMA_DIR must be set.")
suite.T().Fail()
}

Init(logr.Discard(), schemaDir)
}

// Uncomment this function to check server logs after failure
Expand All @@ -29,52 +39,44 @@ func (suite *GenerateE2eTestSuite) TearDownSuite() {
if err != nil {
suite.T().Fatal(err)
}

}

func (suite *GenerateE2eTestSuite) SetupTest() {
}

func (suite *GenerateE2eTestSuite) TestGenerate() {
Init(logr.Discard(), "/Users/jesseschmidt/Developer/aerospike-admin/lib/live_cluster/client/config-schemas")
asPolicy := aero.NewClientPolicy()
host := aero.NewHost(test.IP, test.PORT_START)
asPolicy.User = "admin"
asPolicy.Password = "admin"

asinfo := info.NewAsInfo(logr.Discard(), host, asPolicy)
genConf, err := GenerateConf(logr.Discard(), asinfo, true)

genConf, err := GenerateConf(logr.Discard(), asinfo, true)
suite.Assert().Nil(err)

genConfWithDefaults, err := GenerateConf(logr.Discard(), asinfo, false)

suite.Assert().Nil(err)

asconf, err := NewMapAsConfig(logr.Discard(), genConf.version, genConf.conf)

suite.Assert().Nil(err)

asconfWithDefaults, err := NewMapAsConfig(logr.Discard(), genConfWithDefaults.version, genConfWithDefaults.conf)

suite.Assert().Nil(err)

test.RestartAerospikeContainer(test.GetAerospikeContainerName(0), asconf.ToConfFile())

asinfo2 := info.NewAsInfo(logr.Discard(), host, asPolicy)
genConf2, err := GenerateConf(logr.Discard(), asinfo2, true)

genConf2, err := GenerateConf(logr.Discard(), asinfo2, true)
suite.Assert().Nil(err)

genConfWithDefaults2, err := GenerateConf(logr.Discard(), asinfo2, false)

suite.Assert().Nil(err)

asconf2, err := NewMapAsConfig(logr.Discard(), genConf2.version, genConf2.conf)

suite.Assert().Nil(err)

asconfWithDefaults2, err := NewMapAsConfig(logr.Discard(), genConfWithDefaults2.version, genConfWithDefaults2.conf)

suite.Assert().Nil(err)

suite.Assert().Equal(asconf, asconf2)
suite.Assert().Equal(asconfWithDefaults, asconfWithDefaults2)
}
Expand Down
Loading

0 comments on commit 644aab9

Please sign in to comment.