From 51bf24a39ae8f0e90db684890d4a0fa1c979f3fb Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:12:02 -0500 Subject: [PATCH 01/10] fix: db root on mac after refactor --- .github/workflows/test.yml | 25 +++++++++++++++++++++++++ internal/config/database.go | 2 +- internal/config/database_linux.go | 2 +- internal/config/database_linux_test.go | 17 +++++++++++++++++ internal/config/database_test.go | 23 +++++++++++++++++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 internal/config/database_linux_test.go create mode 100644 internal/config/database_test.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea8087138e..26a897719f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,6 +42,31 @@ 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: Install Dagger + run: | + cd /usr/local + curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=$DAGGER_VERSION sh + + - name: Install Mage + uses: magefile/mage-action@v3 + with: + install-only: true + + - name: Unit Test SQLite} + run: mage dagger:run "test:database sqlite" + ui: name: "Tests (UI)" runs-on: ubuntu-latest 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")) +} From 013c898699f0a0893d61f43615f31ae03d0e89b4 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:15:15 -0500 Subject: [PATCH 02/10] chore: typo --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26a897719f..85a7110153 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,7 +64,7 @@ jobs: with: install-only: true - - name: Unit Test SQLite} + - name: Unit Test SQLite run: mage dagger:run "test:database sqlite" ui: From 791e843fc9733475c848b927e324d01e05649ec7 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:18:48 -0500 Subject: [PATCH 03/10] chore: try to fix docker issue on mac --- .github/workflows/test.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 85a7110153..a0cf47f60b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,6 +64,15 @@ jobs: with: install-only: true + - name: Setup Docker (Colima) + run: | + brew install docker + colima start + + # For testcontainers to find the Colima socket + # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running + sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock + - name: Unit Test SQLite run: mage dagger:run "test:database sqlite" From ea0dd21517739ef3382e0ca7fdc69cf5de521261 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:38:31 -0500 Subject: [PATCH 04/10] chore: fix default db path --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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{ From 6615fef4a4f49b690e2875e69a0c36999a06d950 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:48:24 -0500 Subject: [PATCH 05/10] chore: run short tests for macos --- .github/workflows/test.yml | 13 +++---------- magefile.go | 9 ++++++++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a0cf47f60b..1eb1acfdc9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,17 +64,10 @@ jobs: with: install-only: true - - name: Setup Docker (Colima) - run: | - brew install docker - colima start - - # For testcontainers to find the Colima socket - # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running - sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock - - name: Unit Test SQLite - run: mage dagger:run "test:database sqlite" + env: + FLIPT_TEST_SHORT: "true" + run: mage test ui: name: "Tests (UI)" diff --git a/magefile.go b/magefile.go index 14f7825cf7..b707b07c98 100644 --- a/magefile.go +++ b/magefile.go @@ -238,7 +238,14 @@ 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", "./...") + 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, "gotest", testArgs...) } type UI mg.Namespace From f222c66449f21186954f60f4dd0401200e38ebce Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:53:45 -0500 Subject: [PATCH 06/10] chore: use go test if no gotest --- magefile.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/magefile.go b/magefile.go index b707b07c98..cda2bff87b 100644 --- a/magefile.go +++ b/magefile.go @@ -238,6 +238,12 @@ func (g Go) Test() error { env["FLIPT_TEST_DATABASE_PROTOCOL"] = os.Getenv("FLIPT_TEST_DATABASE_PROTOCOL") } + testCmd := "go test" + // check of gotest is on path and use that instead + if _, err := exec.LookPath("gotest"); err == nil { + testCmd = "gotest" + } + testArgs := []string{"-v", "-covermode=atomic", "-count=1", "-coverprofile=coverage.txt", "-timeout=60s"} if os.Getenv("FLIPT_TEST_SHORT") != "" { @@ -245,7 +251,7 @@ func (g Go) Test() error { } testArgs = append(testArgs, "./...") - return sh.RunWithV(env, "gotest", testArgs...) + return sh.RunWithV(env, testCmd, testArgs...) } type UI mg.Namespace From e8a90668a1f430dd295e950222a8097886e8d29c Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 14:01:36 -0500 Subject: [PATCH 07/10] chore: wat are you talking about computers!? --- .github/workflows/test.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1eb1acfdc9..c7fae3fa3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,20 +54,10 @@ jobs: check-latest: true cache: true - - name: Install Dagger - run: | - cd /usr/local - curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=$DAGGER_VERSION sh - - - name: Install Mage - uses: magefile/mage-action@v3 - with: - install-only: true - - name: Unit Test SQLite env: FLIPT_TEST_SHORT: "true" - run: mage test + run: go test -v -count=1 -timeout=60s -short ./... ui: name: "Tests (UI)" From 5e9fe5b0713efcb8ff3b44c37249a6d77165e426 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 14:10:05 -0500 Subject: [PATCH 08/10] chore: fix mage test --- magefile.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/magefile.go b/magefile.go index cda2bff87b..1ee3db8c6f 100644 --- a/magefile.go +++ b/magefile.go @@ -238,13 +238,18 @@ func (g Go) Test() error { env["FLIPT_TEST_DATABASE_PROTOCOL"] = os.Getenv("FLIPT_TEST_DATABASE_PROTOCOL") } - testCmd := "go test" + var ( + testCmd = "gotest" + testArgs = []string{} + ) + // check of gotest is on path and use that instead - if _, err := exec.LookPath("gotest"); err == nil { - testCmd = "gotest" + if _, err := exec.LookPath("gotest"); err != nil { + testCmd = "go" + testArgs = append(testArgs, "test") } - testArgs := []string{"-v", "-covermode=atomic", "-count=1", "-coverprofile=coverage.txt", "-timeout=60s"} + testArgs = append(testArgs, []string{"-v", "-covermode=atomic", "-count=1", "-coverprofile=coverage.txt", "-timeout=60s"}...) if os.Getenv("FLIPT_TEST_SHORT") != "" { testArgs = append(testArgs, "-short") From a8d0bd64cfd4a093ca11a6fbf3fe50c2b6b06ddd Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 14:23:39 -0500 Subject: [PATCH 09/10] chore: fix validation test --- rpc/flipt/validation_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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", From c24d3e10e795efbd0a8da45358852df5cdfb7a34 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sun, 12 Nov 2023 17:01:27 -0500 Subject: [PATCH 10/10] chore: add/fix comment for gotest --- magefile.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magefile.go b/magefile.go index 1ee3db8c6f..bc673ef774 100644 --- a/magefile.go +++ b/magefile.go @@ -243,7 +243,8 @@ func (g Go) Test() error { testArgs = []string{} ) - // check of gotest is on path and use that instead + // 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")