diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea8087138e..c7fae3fa3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,6 +42,23 @@ jobs: - name: Upload Coverage uses: codecov/codecov-action@v3.1.4 + test-darwin: + name: "Tests (Go - Darwin)" + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + check-latest: true + cache: true + + - name: Unit Test SQLite + env: + FLIPT_TEST_SHORT: "true" + run: go test -v -count=1 -timeout=60s -short ./... + ui: name: "Tests (UI)" runs-on: ubuntu-latest diff --git a/internal/config/config.go b/internal/config/config.go index 54aa7827b1..252ee6d228 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -437,7 +437,7 @@ func Default() *Config { panic(err) } - dbPath := filepath.Join(dbRoot, "flipt", "flipt.db") + dbPath := filepath.Join(dbRoot, "flipt.db") return &Config{ Log: LogConfig{ diff --git a/internal/config/database.go b/internal/config/database.go index a419ecc898..44d0056b9f 100644 --- a/internal/config/database.go +++ b/internal/config/database.go @@ -62,7 +62,7 @@ func (c *DatabaseConfig) setDefaults(v *viper.Viper) error { return fmt.Errorf("getting default database directory: %w", err) } - path := filepath.Join(dbRoot, "flipt", "flipt.db") + path := filepath.Join(dbRoot, "flipt.db") v.SetDefault("db.url", "file:"+path) } diff --git a/internal/config/database_linux.go b/internal/config/database_linux.go index f3274f3093..a2b7692085 100644 --- a/internal/config/database_linux.go +++ b/internal/config/database_linux.go @@ -4,5 +4,5 @@ package config func defaultDatabaseRoot() (string, error) { - return "/var/opt", nil + return "/var/opt/flipt", nil } diff --git a/internal/config/database_linux_test.go b/internal/config/database_linux_test.go new file mode 100644 index 0000000000..27126b6ce7 --- /dev/null +++ b/internal/config/database_linux_test.go @@ -0,0 +1,17 @@ +//go:build linux +// +build linux + +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestDefaultDatabaseRoot(t *testing.T) { + root, err := defaultDatabaseRoot() + require.NoError(t, err) + assert.Equal(t, "/var/opt/flipt", root) +} diff --git a/internal/config/database_test.go b/internal/config/database_test.go new file mode 100644 index 0000000000..db12a07513 --- /dev/null +++ b/internal/config/database_test.go @@ -0,0 +1,23 @@ +//go:build !linux +// +build !linux + +package config + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestDefaultDatabaseRoot(t *testing.T) { + root, err := defaultDatabaseRoot() + require.NoError(t, err) + + configDir, err := os.UserConfigDir() + require.NoError(t, err) + + assert.Equal(t, root, filepath.Join(configDir, "flipt")) +} diff --git a/magefile.go b/magefile.go index 14f7825cf7..bc673ef774 100644 --- a/magefile.go +++ b/magefile.go @@ -238,7 +238,26 @@ func (g Go) Test() error { env["FLIPT_TEST_DATABASE_PROTOCOL"] = os.Getenv("FLIPT_TEST_DATABASE_PROTOCOL") } - return sh.RunWithV(env, "gotest", "-v", "-covermode=atomic", "-count=1", "-coverprofile=coverage.txt", "-timeout=60s", "./...") + var ( + testCmd = "gotest" + testArgs = []string{} + ) + + // check if gotest is on path and use that instead for better output + // https://github.com/rakyll/gotest + if _, err := exec.LookPath("gotest"); err != nil { + testCmd = "go" + testArgs = append(testArgs, "test") + } + + testArgs = append(testArgs, []string{"-v", "-covermode=atomic", "-count=1", "-coverprofile=coverage.txt", "-timeout=60s"}...) + + if os.Getenv("FLIPT_TEST_SHORT") != "" { + testArgs = append(testArgs, "-short") + } + + testArgs = append(testArgs, "./...") + return sh.RunWithV(env, testCmd, testArgs...) } type UI mg.Namespace diff --git a/rpc/flipt/validation_test.go b/rpc/flipt/validation_test.go index bc3959fa86..bb8b5f26e8 100644 --- a/rpc/flipt/validation_test.go +++ b/rpc/flipt/validation_test.go @@ -612,7 +612,7 @@ func TestValidate_CreateRuleRequest(t *testing.T) { SegmentKey: "", Rank: 1, }, - wantErr: errors.EmptyFieldError("segmentKey"), + wantErr: errors.EmptyFieldError("segmentKey or segmentKeys"), }, { name: "rankLessThanZero", @@ -677,7 +677,7 @@ func TestValidate_UpdateRuleRequest(t *testing.T) { FlagKey: "flagKey", SegmentKey: "", }, - wantErr: errors.EmptyFieldError("segmentKey"), + wantErr: errors.EmptyFieldError("segmentKey or segmentKeys"), }, { name: "valid", @@ -1672,7 +1672,7 @@ func TestValidate_CreateRolloutRequest(t *testing.T) { }, }, }, - wantErr: errors.EmptyFieldError("segmentKey"), + wantErr: errors.EmptyFieldError("segmentKey or segmentKeys"), }, { name: "valid", @@ -1751,7 +1751,7 @@ func TestValidate_UpdateRolloutRequest(t *testing.T) { }, }, }, - wantErr: errors.EmptyFieldError("segmentKey"), + wantErr: errors.EmptyFieldError("segmentKey or segmentKeys"), }, { name: "valid",