diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a92f4a6..59a1190 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,7 +1,7 @@ name: Go Build on: [push] jobs: - build: + linux: runs-on: ubuntu-latest steps: - name: Set up Go @@ -25,6 +25,27 @@ jobs: with: path-to-profile: ./build/test-all.cover + + macos: + runs-on: macos-latest + steps: + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.25 + cache: false + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build and tests + env: + BASH_COMPAT: 3.2 + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} + LANG: en_US.UTF-8 + run: make all + + release: runs-on: ubuntu-latest permissions: diff --git a/config/config_test.go b/config/config_test.go index 5744235..a44a55f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -14,6 +14,7 @@ import ( "github.com/tkrop/go-config/config" "github.com/tkrop/go-config/internal/filepath" "github.com/tkrop/go-testing/mock" + ref "github.com/tkrop/go-testing/reflect" "github.com/tkrop/go-testing/test" ) @@ -66,7 +67,7 @@ var configTestCases = map[string]ConfigParams{ r.SetDefault("viper.panic.load", true) }, expect: test.Panic(config.NewErrConfig("loading file", "test", - test.NewBuilder[viper.ConfigFileNotFoundError](). + ref.NewBuilder[viper.ConfigFileNotFoundError](). Set("locations", fmt.Sprintf("%s", configPaths)). Set("name", "test").Build())), }, @@ -92,7 +93,7 @@ var configTestCases = map[string]ConfigParams{ }, expect: test.Panic(config.NewErrConfig("unmarshal config", "test", fmt.Errorf("decoding failed due to the following error(s):\n\n%w", - errors.Join(test.NewBuilder[*mapstructure.DecodeError](). + errors.Join(ref.NewBuilder[*mapstructure.DecodeError](). Set("name", "Info.Dirty"). Set("err", &mapstructure.ParseError{ Expected: reflect.ValueOf(true), Value: "5s", @@ -103,7 +104,8 @@ var configTestCases = map[string]ConfigParams{ func TestConfig(t *testing.T) { test.Map(t, configTestCases). - Filter("panic-after-unmarshal-failure-next", false). + Filter(test.Not(test.Pattern[ConfigParams]( + "panic-after-unmarshal-failure-next"))). RunSeq(func(t test.Test, param ConfigParams) { // Given mock.NewMocks(t).Expect(param.expect) diff --git a/go.mod b/go.mod index 16f5244..3ab4d07 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/tkrop/go-config -go 1.25.3 +go 1.25.4 require ( github.com/go-viper/mapstructure/v2 v2.4.0 @@ -9,7 +9,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 - github.com/tkrop/go-testing v0.0.36 + github.com/tkrop/go-testing v0.0.41 go.uber.org/mock v0.6.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -23,7 +23,7 @@ require ( github.com/pelletier/go-toml v1.2.0 // indirect github.com/spf13/jwalterweatherman v1.0.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect - golang.org/x/sys v0.37.0 // indirect + golang.org/x/sys v0.38.0 // indirect gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/yaml.v2 v2.2.8 // indirect ) diff --git a/go.sum b/go.sum index a2ac797..ae8e154 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/tkrop/go-testing v0.0.36 h1:zqdegv/3kYN/YeFrVdicQ5pk1HXAy+kp3sjV/1Az1U4= github.com/tkrop/go-testing v0.0.36/go.mod h1:zA+nf5U80EqqEBuRF8PaRjium1UcQmyX27usZCd+fcE= +github.com/tkrop/go-testing v0.0.41 h1:TibdqoYj+DMangabEkETgujITlMwZA9b+IGTjRMtpRE= +github.com/tkrop/go-testing v0.0.41/go.mod h1:zA+nf5U80EqqEBuRF8PaRjium1UcQmyX27usZCd+fcE= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= @@ -112,8 +114,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= -golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= +golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/filepath/path.go b/internal/filepath/path.go index 5e37c3f..5896b56 100644 --- a/internal/filepath/path.go +++ b/internal/filepath/path.go @@ -4,6 +4,7 @@ package filepath import ( "os" "path/filepath" + "runtime" ) // Normalize the given path by expanding environment variables, resolving the @@ -11,7 +12,7 @@ import ( func Normalize(path string) string { path = os.ExpandEnv(path) - if filepath.IsAbs(path) { + if runtime.GOOS != "darwin" && filepath.IsAbs(path) { return filepath.Clean(path) } diff --git a/internal/filepath/path_test.go b/internal/filepath/path_test.go index c075471..6d42c71 100644 --- a/internal/filepath/path_test.go +++ b/internal/filepath/path_test.go @@ -63,6 +63,8 @@ var normalizeTestCases = map[string]NormalizeParams{ func TestNormalize(t *testing.T) { test.Map(t, normalizeTestCases). + Filter(test.Not(test.And(test.OS[NormalizeParams]("darwin"), + test.Pattern[NormalizeParams]("path expand error")))). RunSeq(func(t test.Test, param NormalizeParams) { // Given if param.setup != nil { diff --git a/log/buffer_test.go b/log/buffer_test.go index b268487..ad6fc87 100644 --- a/log/buffer_test.go +++ b/log/buffer_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/tkrop/go-config/log" "github.com/tkrop/go-testing/mock" + "github.com/tkrop/go-testing/reflect" "github.com/tkrop/go-testing/test" ) @@ -290,7 +291,7 @@ func TestBufferWrite(t *testing.T) { buffer := log.NewBuffer(pretty, setupWriter(mocks, param.expect)) - test.NewAccessor(buffer).Set("err", param.error) + reflect.NewAccessor(buffer).Set("err", param.error) // When param.setup(buffer) diff --git a/log/zerolog_test.go b/log/zerolog_test.go index c054065..58f8bcc 100644 --- a/log/zerolog_test.go +++ b/log/zerolog_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tkrop/go-testing/mock" + "github.com/tkrop/go-testing/reflect" "github.com/tkrop/go-testing/test" "github.com/tkrop/go-config/config" @@ -32,7 +33,7 @@ func TestSetupZero(t *testing.T) { log.ParseLevel(logger.GetLevel().String())) // Check if the writer is set up correctly. - writer := test.NewAccessor(logger).Get("w") + writer := reflect.NewAccessor(logger).Get("w") require.IsType(t, zerolog.LevelWriterAdapter{}, writer) adapter, ok := writer.(zerolog.LevelWriterAdapter) require.True(t, ok) @@ -66,7 +67,7 @@ func TestSetupZero(t *testing.T) { } // Check if the hooks are set up with caller hook. - hooks := test.NewAccessor(logger).Get("hooks") + hooks := reflect.NewAccessor(logger).Get("hooks") require.IsType(t, []zerolog.Hook{}, hooks) hookSlice, ok := hooks.([]zerolog.Hook) require.True(t, ok) @@ -482,8 +483,8 @@ func TestZeroLog(t *testing.T) { r.SetDefault("log.level", "trace") }).GetConfig("zerolog") logger := config.Log.SetupZero(buffer).ZeroLogger() - pretty := test.NewAccessor(logger).Get("w").(zerolog.LevelWriterAdapter). - Writer.(*log.ZeroLogPretty) + pretty := reflect.NewAccessor(logger). + Get("w").(zerolog.LevelWriterAdapter).Writer.(*log.ZeroLogPretty) pretty.ColorMode = param.config.ColorMode.Parse(!param.noTerminal) if param.expect != nil {