Skip to content

Commit 501e146

Browse files
authored
feat: add testing for macos (#39)
Signed-off-by: Tronje Krop <[email protected]>
1 parent 7d00e4f commit 501e146

File tree

8 files changed

+45
-15
lines changed

8 files changed

+45
-15
lines changed

.github/workflows/build.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Go Build
22
on: [push]
33
jobs:
4-
build:
4+
linux:
55
runs-on: ubuntu-latest
66
steps:
77
- name: Set up Go
@@ -25,6 +25,27 @@ jobs:
2525
with:
2626
path-to-profile: ./build/test-all.cover
2727

28+
29+
macos:
30+
runs-on: macos-latest
31+
steps:
32+
- name: Set up Go
33+
uses: actions/setup-go@v5
34+
with:
35+
go-version: 1.25
36+
cache: false
37+
38+
- name: Checkout code
39+
uses: actions/checkout@v4
40+
41+
- name: Build and tests
42+
env:
43+
BASH_COMPAT: 3.2
44+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
45+
LANG: en_US.UTF-8
46+
run: make all
47+
48+
2849
release:
2950
runs-on: ubuntu-latest
3051
permissions:

config/config_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/tkrop/go-config/config"
1515
"github.com/tkrop/go-config/internal/filepath"
1616
"github.com/tkrop/go-testing/mock"
17+
ref "github.com/tkrop/go-testing/reflect"
1718
"github.com/tkrop/go-testing/test"
1819
)
1920

@@ -66,7 +67,7 @@ var configTestCases = map[string]ConfigParams{
6667
r.SetDefault("viper.panic.load", true)
6768
},
6869
expect: test.Panic(config.NewErrConfig("loading file", "test",
69-
test.NewBuilder[viper.ConfigFileNotFoundError]().
70+
ref.NewBuilder[viper.ConfigFileNotFoundError]().
7071
Set("locations", fmt.Sprintf("%s", configPaths)).
7172
Set("name", "test").Build())),
7273
},
@@ -92,7 +93,7 @@ var configTestCases = map[string]ConfigParams{
9293
},
9394
expect: test.Panic(config.NewErrConfig("unmarshal config",
9495
"test", fmt.Errorf("decoding failed due to the following error(s):\n\n%w",
95-
errors.Join(test.NewBuilder[*mapstructure.DecodeError]().
96+
errors.Join(ref.NewBuilder[*mapstructure.DecodeError]().
9697
Set("name", "Info.Dirty").
9798
Set("err", &mapstructure.ParseError{
9899
Expected: reflect.ValueOf(true), Value: "5s",
@@ -103,7 +104,8 @@ var configTestCases = map[string]ConfigParams{
103104

104105
func TestConfig(t *testing.T) {
105106
test.Map(t, configTestCases).
106-
Filter("panic-after-unmarshal-failure-next", false).
107+
Filter(test.Not(test.Pattern[ConfigParams](
108+
"panic-after-unmarshal-failure-next"))).
107109
RunSeq(func(t test.Test, param ConfigParams) {
108110
// Given
109111
mock.NewMocks(t).Expect(param.expect)

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/tkrop/go-config
22

3-
go 1.25.3
3+
go 1.25.4
44

55
require (
66
github.com/go-viper/mapstructure/v2 v2.4.0
@@ -9,7 +9,7 @@ require (
99
github.com/sirupsen/logrus v1.9.3
1010
github.com/spf13/viper v1.21.0
1111
github.com/stretchr/testify v1.11.1
12-
github.com/tkrop/go-testing v0.0.36
12+
github.com/tkrop/go-testing v0.0.41
1313
go.uber.org/mock v0.6.0
1414
gopkg.in/yaml.v3 v3.0.1
1515
)
@@ -23,7 +23,7 @@ require (
2323
github.com/pelletier/go-toml v1.2.0 // indirect
2424
github.com/spf13/jwalterweatherman v1.0.0 // indirect
2525
go.yaml.in/yaml/v3 v3.0.4 // indirect
26-
golang.org/x/sys v0.37.0 // indirect
26+
golang.org/x/sys v0.38.0 // indirect
2727
gopkg.in/ini.v1 v1.51.0 // indirect
2828
gopkg.in/yaml.v2 v2.2.8 // indirect
2929
)

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
9696
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
9797
github.com/tkrop/go-testing v0.0.36 h1:zqdegv/3kYN/YeFrVdicQ5pk1HXAy+kp3sjV/1Az1U4=
9898
github.com/tkrop/go-testing v0.0.36/go.mod h1:zA+nf5U80EqqEBuRF8PaRjium1UcQmyX27usZCd+fcE=
99+
github.com/tkrop/go-testing v0.0.41 h1:TibdqoYj+DMangabEkETgujITlMwZA9b+IGTjRMtpRE=
100+
github.com/tkrop/go-testing v0.0.41/go.mod h1:zA+nf5U80EqqEBuRF8PaRjium1UcQmyX27usZCd+fcE=
99101
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
100102
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
101103
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
112114
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
113115
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
114116
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
115-
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
116-
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
117+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
118+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
117119
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
118120
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
119121
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

internal/filepath/path.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ package filepath
44
import (
55
"os"
66
"path/filepath"
7+
"runtime"
78
)
89

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

14-
if filepath.IsAbs(path) {
15+
if runtime.GOOS != "darwin" && filepath.IsAbs(path) {
1516
return filepath.Clean(path)
1617
}
1718

internal/filepath/path_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ var normalizeTestCases = map[string]NormalizeParams{
6363

6464
func TestNormalize(t *testing.T) {
6565
test.Map(t, normalizeTestCases).
66+
Filter(test.Not(test.And(test.OS[NormalizeParams]("darwin"),
67+
test.Pattern[NormalizeParams]("path expand error")))).
6668
RunSeq(func(t test.Test, param NormalizeParams) {
6769
// Given
6870
if param.setup != nil {

log/buffer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stretchr/testify/assert"
99
"github.com/tkrop/go-config/log"
1010
"github.com/tkrop/go-testing/mock"
11+
"github.com/tkrop/go-testing/reflect"
1112
"github.com/tkrop/go-testing/test"
1213
)
1314

@@ -290,7 +291,7 @@ func TestBufferWrite(t *testing.T) {
290291

291292
buffer := log.NewBuffer(pretty,
292293
setupWriter(mocks, param.expect))
293-
test.NewAccessor(buffer).Set("err", param.error)
294+
reflect.NewAccessor(buffer).Set("err", param.error)
294295

295296
// When
296297
param.setup(buffer)

log/zerolog_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
"github.com/tkrop/go-testing/mock"
13+
"github.com/tkrop/go-testing/reflect"
1314
"github.com/tkrop/go-testing/test"
1415

1516
"github.com/tkrop/go-config/config"
@@ -32,7 +33,7 @@ func TestSetupZero(t *testing.T) {
3233
log.ParseLevel(logger.GetLevel().String()))
3334

3435
// Check if the writer is set up correctly.
35-
writer := test.NewAccessor(logger).Get("w")
36+
writer := reflect.NewAccessor(logger).Get("w")
3637
require.IsType(t, zerolog.LevelWriterAdapter{}, writer)
3738
adapter, ok := writer.(zerolog.LevelWriterAdapter)
3839
require.True(t, ok)
@@ -66,7 +67,7 @@ func TestSetupZero(t *testing.T) {
6667
}
6768

6869
// Check if the hooks are set up with caller hook.
69-
hooks := test.NewAccessor(logger).Get("hooks")
70+
hooks := reflect.NewAccessor(logger).Get("hooks")
7071
require.IsType(t, []zerolog.Hook{}, hooks)
7172
hookSlice, ok := hooks.([]zerolog.Hook)
7273
require.True(t, ok)
@@ -482,8 +483,8 @@ func TestZeroLog(t *testing.T) {
482483
r.SetDefault("log.level", "trace")
483484
}).GetConfig("zerolog")
484485
logger := config.Log.SetupZero(buffer).ZeroLogger()
485-
pretty := test.NewAccessor(logger).Get("w").(zerolog.LevelWriterAdapter).
486-
Writer.(*log.ZeroLogPretty)
486+
pretty := reflect.NewAccessor(logger).
487+
Get("w").(zerolog.LevelWriterAdapter).Writer.(*log.ZeroLogPretty)
487488
pretty.ColorMode = param.config.ColorMode.Parse(!param.noTerminal)
488489

489490
if param.expect != nil {

0 commit comments

Comments
 (0)