Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Go Build
on: [push]
jobs:
build:
linux:
runs-on: ubuntu-latest
steps:
- name: Set up Go
Expand All @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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())),
},
Expand All @@ -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",
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
)
Expand All @@ -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
)
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion internal/filepath/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ package filepath
import (
"os"
"path/filepath"
"runtime"
)

// Normalize the given path by expanding environment variables, resolving the
// absolute path, and cleaning the path.
func Normalize(path string) string {
path = os.ExpandEnv(path)

if filepath.IsAbs(path) {
if runtime.GOOS != "darwin" && filepath.IsAbs(path) {
return filepath.Clean(path)
}

Expand Down
2 changes: 2 additions & 0 deletions internal/filepath/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion log/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions log/zerolog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Loading