Skip to content

Commit

Permalink
add test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Jun 10, 2024
1 parent f7bfa33 commit af6c217
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 151 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test
on:
push:
branches-ignore:
- 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: Write feature keys
env:
FEATURES_CONF : ${{secrets.FEATURES_CONF}}

run: |
echo "$FEATURES_CONF" > docker/config/features.conf
- name: Run tests
run: |
make coverage
# - name: Upload coverage to Codecov // Add when public
# uses: codecov/codecov-action@v3
# with:
# token: ${{secrets.CODECOV_TOKEN}}
# files: testdata/coverage/total.cov
# verbose: false
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/docker/*
/bin/*
embed_*.go
/tmp
/tmp
/vendor
/coverage
31 changes: 30 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.NOTPARALLEL:

# TODO: move build/pkg related makefile jobs to pkg/

## requirements: make dpkg rpmbuild upx golang zip wget jq
## macos pkg requirement: https://docker-laptop.s3.eu-west-1.amazonaws.com/Packages.pkg

Expand All @@ -9,7 +11,11 @@ INSTALLSIGNER := "$(asvec_installsigner)"
APPLEID := "$(asvec_appleid)"
APPLEPW := "$(asvec_applepw)"
TEAMID := "$(asvec_teamid)"
ROOT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR = ./bin
COVERAGE_DIR = $(ROOT_DIR)/coverage
COV_UNIT_DIR = $(COVERAGE_DIR)/unit
COV_INTEGRATION_DIR = $(COVERAGE_DIR)/integration

## available make commands
.PHONY: help
Expand Down Expand Up @@ -488,4 +494,27 @@ macos-pkg-notarize:
fi

### make cleanall && make build-prerelease && make pkg-linux && make pkg-windows-zip && make macos-build-all && make macos-notarize-all
### make cleanall && make build-official && make pkg-linux && make pkg-windows-zip && make macos-build-all && make macos-notarize-all
### make cleanall && make build-official && make pkg-linux && make pkg-windows-zip && make macos-build-all && make macos-notarize-all

.PHONY: test
test: integration unit

.PHONY: integration
integration:
mkdir -p $(COV_INTEGRATION_DIR) || true
COVERAGE_DIR=$(COV_INTEGRATION_DIR) go test -tags=integration -timeout 30m

.PHONY: unit
unit:
mkdir -p $(COV_UNIT_DIR) || true
go test -tags=unit -cover ./... -args -test.gocoverdir=$(COV_UNIT_DIR)

.PHONY: coverage
coverage: test
go tool covdata textfmt -i="$(COV_INTEGRATION_DIR),$(COV_UNIT_DIR)" -o=$(COVERAGE_DIR)/total.cov
go tool cover -func=$(COVERAGE_DIR)/total.cov


PHONY: view-coverage
view-coverage: $(COVERAGE_DIR)/total.cov
go tool cover -html=$(COVERAGE_DIR)/total.cov
3 changes: 2 additions & 1 deletion cmd/createIndex.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"log/slog"
"strings"
"time"

avs "github.com/aerospike/aerospike-proximus-client-go"
Expand Down Expand Up @@ -62,7 +63,7 @@ func newCreateIndexFlagSet() *pflag.FlagSet {
flagSet.StringVarP(&createIndexFlags.indexName, flagNameIndexName, "i", "", commonFlags.DefaultWrapHelpString("The name of the index.")) //nolint:lll // For readability
flagSet.StringVarP(&createIndexFlags.vectorField, flagNameVectorField, "f", "", commonFlags.DefaultWrapHelpString("The name of the vector field.")) //nolint:lll // For readability
flagSet.Uint32VarP(&createIndexFlags.dimensions, flagNameDimension, "d", 0, commonFlags.DefaultWrapHelpString("The dimension of the vector field.")) //nolint:lll // For readability
flagSet.VarP(&createIndexFlags.distanceMetric, flagNameDistanceMetric, "m", commonFlags.DefaultWrapHelpString("The distance metric for the index.")) //nolint:lll // For readability
flagSet.VarP(&createIndexFlags.distanceMetric, flagNameDistanceMetric, "m", commonFlags.DefaultWrapHelpString(fmt.Sprintf("The distance metric for the index. Valid values: %s", strings.Join(flags.DistanceMetricEnum(), ", ")))) //nolint:lll // For readability
flagSet.StringToStringVar(&createIndexFlags.indexMeta, flagNameIndexMeta, nil, commonFlags.DefaultWrapHelpString("The distance metric for the index.")) //nolint:lll // For readability
flagSet.DurationVar(&createIndexFlags.timeout, flagNameTimeout, time.Second*5, commonFlags.DefaultWrapHelpString("The distance metric for the index.")) //nolint:lll // For readability
flagSet.Var(&createIndexFlags.storageNamespace, flagNameStorageNamespace, commonFlags.DefaultWrapHelpString("Optional storage namespace where the index is stored. Defaults to the index namespace.")) //nolint:lll // For readability //nolint:lll // For readability
Expand Down
14 changes: 9 additions & 5 deletions cmd/flags/distanceMetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ func (f *DistanceMetricFlag) Set(val string) error {
}

func (f *DistanceMetricFlag) Type() string {
return "enum"
}

func (f *DistanceMetricFlag) String() string {
return string(*f)
}

func DistanceMetricEnum() []string {
names := []string{}

for key := range distanceMetricSet {
Expand All @@ -32,9 +40,5 @@ func (f *DistanceMetricFlag) Type() string {

slices.Sort(names)

return strings.Join(names, ",")
}

func (f *DistanceMetricFlag) String() string {
return string(*f)
return names
}
8 changes: 7 additions & 1 deletion cmd/flags/distanceMetric_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package flags

import (
Expand Down Expand Up @@ -60,7 +62,7 @@ func (suite *DistanceMetricFlagTestSuite) TestSet() {

func (suite *DistanceMetricFlagTestSuite) TestType() {
flag := DistanceMetricFlag("")
suite.Equal("COSINE,DOT_PRODUCT,HAMMING,MANHATTAN,SQUARED_EUCLIDEAN", flag.Type())
suite.Equal("enum", flag.Type())
}

func (suite *DistanceMetricFlagTestSuite) TestString() {
Expand All @@ -74,6 +76,10 @@ func (suite *DistanceMetricFlagTestSuite) TestString() {
suite.Equal("manhattan", flag.String())
}

func (suite *DistanceMetricFlagTestSuite) TestDistanceMetricEnum() {
suite.Equal([]string{"COSINE", "DOT_PRODUCT", "HAMMING", "MANHATTAN", "SQUARED_EUCLIDEAN"}, DistanceMetricEnum())
}

func TestDistanceMetricFlagSuite(t *testing.T) {
suite.Run(t, new(DistanceMetricFlagTestSuite))
}
2 changes: 2 additions & 0 deletions cmd/flags/hostPort_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package flags

import (
Expand Down
14 changes: 9 additions & 5 deletions cmd/flags/logLevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func (f *LogLevelFlag) Set(val string) error {
}

func (f *LogLevelFlag) Type() string {
return "enum"
}

func (f *LogLevelFlag) String() string {
return string(*f)
}

func LogLevelEnum() []string {
names := []string{}

for key := range logLevelSet {
Expand All @@ -45,9 +53,5 @@ func (f *LogLevelFlag) Type() string {
return logLevelSet[names[i]] < logLevelSet[names[j]]
})

return strings.Join(names, ",")
}

func (f *LogLevelFlag) String() string {
return string(*f)
return names
}
8 changes: 7 additions & 1 deletion cmd/flags/logLevel_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package flags

import (
Expand Down Expand Up @@ -35,10 +37,14 @@ func (suite *LogLevelSuite) TestSet() {

func (suite *LogLevelSuite) TestType() {
flag := LogLevelFlag("")
suite.Equal("DEBUG,INFO,WARN,ERROR", flag.Type())
suite.Equal("enum", flag.Type())
}

func (suite *LogLevelSuite) TestString() {
flag := LogLevelFlag("DEBUG")
suite.Equal("DEBUG", flag.String())
}

func (suite *LogLevelSuite) TestLogLevelEnum() {
suite.Equal([]string{"DEBUG", "INFO", "WARN", "ERROR"}, LogLevelEnum())
}
2 changes: 2 additions & 0 deletions cmd/flags/optionals_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package flags

import (
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log/slog"
"os"
"strings"

common "github.com/aerospike/tools-common-go/flags"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -85,7 +86,7 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().Var(&rootFlags.logLevel, logLevelFlagName, "Log level for additional details and debugging")
rootCmd.PersistentFlags().Var(&rootFlags.logLevel, logLevelFlagName, common.DefaultWrapHelpString(fmt.Sprintf("Log level for additional details and debugging. Valid values: %s", strings.Join(flags.LogLevelEnum(), ", "))))
common.SetupRoot(rootCmd, "aerospike-vector-search", "0.0.0") // TODO: Handle version
viper.SetEnvPrefix("ASVEC")

Expand Down
Loading

0 comments on commit af6c217

Please sign in to comment.