Skip to content

Commit

Permalink
fix: db root on mac after refactor (#2373)
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps authored Nov 13, 2023
1 parent 8382bd2 commit 0571dff
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 8 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ jobs:
- name: Upload Coverage
uses: codecov/[email protected]

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
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/database_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
package config

func defaultDatabaseRoot() (string, error) {
return "/var/opt", nil
return "/var/opt/flipt", nil
}
17 changes: 17 additions & 0 deletions internal/config/database_linux_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 23 additions & 0 deletions internal/config/database_test.go
Original file line number Diff line number Diff line change
@@ -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"))
}
21 changes: 20 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions rpc/flipt/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1672,7 +1672,7 @@ func TestValidate_CreateRolloutRequest(t *testing.T) {
},
},
},
wantErr: errors.EmptyFieldError("segmentKey"),
wantErr: errors.EmptyFieldError("segmentKey or segmentKeys"),
},
{
name: "valid",
Expand Down Expand Up @@ -1751,7 +1751,7 @@ func TestValidate_UpdateRolloutRequest(t *testing.T) {
},
},
},
wantErr: errors.EmptyFieldError("segmentKey"),
wantErr: errors.EmptyFieldError("segmentKey or segmentKeys"),
},
{
name: "valid",
Expand Down

0 comments on commit 0571dff

Please sign in to comment.