Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Jan 9, 2024
1 parent 88f40d7 commit a6710df
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
run: |
make coverage
env:
FEATKEY : /tmp
FEATKEY_DIR : /tmp
ASC_DOCKER_USER : ${{secrets.DOCKER_USER}}
ASC_DOCKER_PASS : ${{secrets.DOCKER_PASS}}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ make unit
### Integration Tests

Integration tests require that docker is installed and running.
A path to an Aerospike feature key file should be defined at the `FEATKEY` environment variable.
A path to an Aerospike feature key file should be defined at the `FEATKEY_DIR` environment variable.
For more information about the feature key file see the [feature-key docs](https://docs.aerospike.com/server/operations/configure/feature-key).

```shell
FEATKEY=/path/to/aerospike/features.conf make integration
FEATKEY_DIR=/path/to/aerospike/features/dir make integration
```

### All Tests

```shell
FEATKEY=/path/to/aerospike/features.conf make test
FEATKEY_DIR=/path/to/aerospike/features/dir make test
```

### Test Coverage

```shell
FEATKEY=/path/to/aerospike/features.conf make view-coverage
FEATKEY_DIR=/path/to/aerospike/features/dir make view-coverage
```
22 changes: 19 additions & 3 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/aerospike/aerospike-management-lib/asconfig"
"github.com/aerospike/asconfig/conf"
Expand Down Expand Up @@ -151,9 +153,23 @@ func newConvertCmd() *cobra.Command {
return err
}

err = CheckIsDir(&outputPath, outFmt)
if err != nil {
return err
if stat, err := os.Stat(outputPath); !errors.Is(err, os.ErrNotExist) && stat.IsDir() {
// output path is a directory so write a new file to it
outFileName := filepath.Base(srcPath)
if srcPath == os.Stdin.Name() {
outFileName = defaultOutputFileName
}

outFileName = strings.TrimSuffix(outFileName, filepath.Ext(outFileName))

outputPath = filepath.Join(outputPath, outFileName)
if outFmt == conf.YAML {
outputPath += ".yaml"
} else if outFmt == conf.AsConfig {
outputPath += ".conf"
} else {
return fmt.Errorf("output format unrecognized %w", errInvalidFormat)
}
}

var outFile *os.File
Expand Down
8 changes: 1 addition & 7 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ func newGenerateCmd() *cobra.Command {
return errors.Join(fmt.Errorf("unable to marshal the generated conf file"), err)
}

err = CheckIsDir(&outputPath, outFormat)

if err != nil {
return err
}

mdata := map[string]string{
metaKeyAerospikeVersion: generatedConf.Version,
metaKeyAsconfigVersion: VERSION,
Expand Down Expand Up @@ -130,7 +124,7 @@ func newGenerateCmd() *cobra.Command {
flags.SetAerospikeFlags(asCommonFlags, flags.DefaultWrapHelpString),
)
res.Flags().StringP("output", "o", os.Stdout.Name(), flags.DefaultWrapHelpString("File path to write output to"))
res.Flags().StringP("format", "F", "conf", "The format of the destination file(s). Valid options are: yaml, yml, and conf.")
res.Flags().StringP("format", "F", "conf", flags.DefaultWrapHelpString("The format of the destination file(s). Valid options are: yaml, yml, and conf."))

return res
}
24 changes: 0 additions & 24 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -131,26 +130,3 @@ func ParseFmtString(in string) (f conf.Format, err error) {

return
}

func CheckIsDir(outputPath *string, outFormat conf.Format) error {
if stat, err := os.Stat(*outputPath); !errors.Is(err, os.ErrNotExist) && stat.IsDir() {
// output path is a directory so write a new file to it
outFileName := filepath.Base(*outputPath)
if *outputPath == os.Stdin.Name() {
outFileName = defaultOutputFileName
}

outFileName = strings.TrimSuffix(outFileName, filepath.Ext(outFileName))

*outputPath = filepath.Join(*outputPath, outFileName)
if outFormat == conf.YAML {
*outputPath += ".yaml"
} else if outFormat == conf.AsConfig {
*outputPath += ".conf"
} else {
return fmt.Errorf("output format unrecognized %w", errInvalidFormat)
}
}

return nil
}
25 changes: 11 additions & 14 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
)

const (
sourcePath = "testdata/sources"
expectedPath = "testdata/expected"
destinationPath = "testdata/destinations"
coveragePath = "testdata/coverage/integration"
binPath = "testdata/bin"
extraTestPath = "testdata/cases"
tmpServerLogPath = "testdata/tmp_server.log"
sourcePath = "/Users/jesseschmidt/Developer/asconfig/testdata/sources"
expectedPath = "/Users/jesseschmidt/Developer/asconfig/testdata/expected"
destinationPath = "/Users/jesseschmidt/Developer/asconfig/testdata/destinations"
coveragePath = "/Users/jesseschmidt/Developer/asconfig/testdata/coverage/integration"
binPath = "/Users/jesseschmidt/Developer/asconfig/testdata/bin"
extraTestPath = "/Users/jesseschmidt/Developer/asconfig/testdata/cases"
tmpServerLogPath = "/Users/jesseschmidt/Developer/asconfig/testdata/tmp_server.log"
)

var featKeyDir string
Expand Down Expand Up @@ -68,10 +68,10 @@ func TestMain(m *testing.M) {
panic(err)
}

featKeyDir = os.Getenv("FEATKEY")
featKeyDir = os.Getenv("FEATKEY_DIR")
fmt.Println(featKeyDir)
if featKeyDir == "" {
panic("FEATKEY environement variable must be full path to a directory containing valid aerospike feature key files featuresv1.conf and featuresv2.conf of feature key format 1 and 2 respectively.")
panic("FEATKEY_DIR environement variable must an absolute path to a directory containing valid aerospike feature key files featuresv1.conf and featuresv2.conf of feature key format 1 and 2 respectively.")
}

code := m.Run()
Expand Down Expand Up @@ -311,6 +311,7 @@ func TestYamlToConf(t *testing.T) {
if !tf.SkipServerTest {
version := getVersion(tf.Arguments)
id := runServer(version, confPath, dockerClient, t, tf)
time.Sleep(time.Second * 1000)

time.Sleep(time.Second * 3) // need this to allow logs to accumulate

Expand Down Expand Up @@ -478,10 +479,6 @@ func runServer(version string, confPath string, dockerClient *client.Client, t *
}

return id

// need this to allow logs to accumulate
time.Sleep(time.Second * 3)

}

func stopServer(id string, dockerClient *client.Client) error {
Expand Down Expand Up @@ -716,7 +713,7 @@ func TestConfToYaml(t *testing.T) {
version := getVersion(tf.Arguments)
id := runServer(version, finalConfPath, dockerClient, t, tf)

time.Sleep(3) // need this to allow logs to accumulate
time.Sleep(time.Second * 3) // need this to allow logs to accumulate

stopServer(id, dockerClient)
checkContainerLogs(id, t, tf, tmpServerLogPath)
Expand Down
12 changes: 11 additions & 1 deletion testdata/cases/server70/conf-tests.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
[{"Source":"testdata/cases/server70/server70.conf","Destination":"testdata/cases/server70/server70-res-.yaml","Expected":"testdata/cases/server70/server70.yaml","Arguments":["convert","--aerospike-version","7.0.0","--format","asconfig","--output","testdata/cases/server70/server70-res-.yaml"],"SkipServerTest":false,"ServerErrorAllowList":null,"ServerImage":"aerospike.jfrog.io/docker-remote/aerospike/aerospike-server-enterprise-rc:7.0.0.0-rc3","DockerAuth":{"Username":"ASC_DOCKER_USER","Password":"ASC_DOCKER_PASS"}}]
[
{
"Source":"testdata/cases/server70/server70.conf",
"Destination":"testdata/cases/server70/server70-res-.yaml",
"Expected":"testdata/cases/server70/server70.yaml",
"Arguments":["convert","--aerospike-version","7.0.0","--format","asconfig","--output","testdata/cases/server70/server70-res-.yaml"],
"SkipServerTest":false,
"ServerErrorAllowList":null,
"ServerImage":"aerospike.jfrog.io/docker-remote/aerospike/aerospike-server-enterprise:7.0.0.3"
}
]
12 changes: 11 additions & 1 deletion testdata/cases/server70/yaml-tests.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
[{"Source":"testdata/cases/server70/server70.yaml","Destination":"testdata/cases/server70/server70-res-.conf","Expected":"testdata/cases/server70/server70.conf","Arguments":["convert","--aerospike-version","7.0.0","--format","yaml","--output","testdata/cases/server70/server70-res-.conf"],"SkipServerTest":false,"ServerErrorAllowList":null,"ServerImage":"aerospike.jfrog.io/docker-remote/aerospike/aerospike-server-enterprise-rc:7.0.0.0-rc3","DockerAuth":{"Username":"ASC_DOCKER_USER","Password":"ASC_DOCKER_PASS"}}]
[
{
"Source":"testdata/cases/server70/server70.yaml",
"Destination":"testdata/cases/server70/server70-res-.conf",
"Expected":"testdata/cases/server70/server70.conf",
"Arguments":["convert","--aerospike-version","7.0.0","--format","yaml","--output","testdata/cases/server70/server70-res-.conf"],
"SkipServerTest":false,
"ServerErrorAllowList":null,
"ServerImage":"aerospike.jfrog.io/docker-remote/aerospike/aerospike-server-enterprise:7.0.0.3"
}
]

0 comments on commit a6710df

Please sign in to comment.