Skip to content

Commit 8385986

Browse files
committed
tests: migrate from shoenig to stretchr/testify
Migrate test assertions from github.com/shoenig/test to github.com/stretchr/testify across the entire test suite. - Update all test files to use `assert.Equal`, `require.NoError`, and other testify assertions. - Remove `shoenig/test` dependency from go.mod and go.sum. - Update golangci.yml to allow testify in test files. - Remove inline comments that are now redundant with clearer testify assertions. - Update testutil helpers to use testify and define minimal TB interface.
1 parent 3270172 commit 8385986

18 files changed

Lines changed: 495 additions & 611 deletions

.golangci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ linters:
6868
- "!$test"
6969
allow:
7070
- $gostd
71-
- "github.com/shoenig/test"
71+
- "github.com/stretchr/testify"
7272
- "go.yaml.in/yaml/v3"
7373
- "github.com/tarantool/go-config"
7474
- "github.com/kaptinlin/jsonschema"
@@ -77,7 +77,6 @@ linters:
7777
- "$test"
7878
allow:
7979
- $gostd
80-
- "github.com/shoenig/test"
8180
- "github.com/stretchr/testify"
8281
- "github.com/tarantool/go-config"
8382
- "github.com/kaptinlin/jsonschema"

builder_test.go

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package config_test
33
import (
44
"testing"
55

6-
"github.com/shoenig/test"
7-
"github.com/shoenig/test/must"
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
88

99
"github.com/tarantool/go-config"
1010
"github.com/tarantool/go-config/collectors"
@@ -13,7 +13,6 @@ import (
1313
func TestConfigBuilder_PortOverride(t *testing.T) {
1414
t.Parallel()
1515

16-
// Create two map collectors with overlapping keys.
1716
map1 := map[string]any{
1817
"server": map[string]any{
1918
"port": 8080,
@@ -22,7 +21,7 @@ func TestConfigBuilder_PortOverride(t *testing.T) {
2221
}
2322
map2 := map[string]any{
2423
"server": map[string]any{
25-
"port": 9090, // Overrides port.
24+
"port": 9090,
2625
},
2726
"log": map[string]any{
2827
"level": "debug",
@@ -38,21 +37,19 @@ func TestConfigBuilder_PortOverride(t *testing.T) {
3837
builder = builder.AddCollector(col2)
3938

4039
cfg, errs := builder.Build()
41-
must.SliceEmpty(t, errs)
40+
require.Empty(t, errs)
4241

43-
// Check that port is overridden by later collector.
4442
var port int
4543

4644
meta, err := cfg.Get(config.NewKeyPath("server/port"), &port)
47-
must.NoError(t, err)
48-
test.Eq(t, 9090, port)
49-
test.Eq(t, "map2", meta.Source.Name)
45+
require.NoError(t, err)
46+
assert.Equal(t, 9090, port)
47+
assert.Equal(t, "map2", meta.Source.Name)
5048
}
5149

5250
func TestConfigBuilder_TimeoutFromFirstCollector(t *testing.T) {
5351
t.Parallel()
5452

55-
// Create two map collectors with overlapping keys.
5653
map1 := map[string]any{
5754
"server": map[string]any{
5855
"port": 8080,
@@ -61,7 +58,7 @@ func TestConfigBuilder_TimeoutFromFirstCollector(t *testing.T) {
6158
}
6259
map2 := map[string]any{
6360
"server": map[string]any{
64-
"port": 9090, // Overrides port.
61+
"port": 9090,
6562
},
6663
"log": map[string]any{
6764
"level": "debug",
@@ -77,21 +74,19 @@ func TestConfigBuilder_TimeoutFromFirstCollector(t *testing.T) {
7774
builder = builder.AddCollector(col2)
7875

7976
cfg, errs := builder.Build()
80-
must.SliceEmpty(t, errs)
77+
require.Empty(t, errs)
8178

82-
// Check timeout from first collector.
8379
var timeout string
8480

8581
meta, err := cfg.Get(config.NewKeyPath("server/timeout"), &timeout)
86-
must.NoError(t, err)
87-
test.Eq(t, "30s", timeout)
88-
test.Eq(t, "map1", meta.Source.Name)
82+
require.NoError(t, err)
83+
assert.Equal(t, "30s", timeout)
84+
assert.Equal(t, "map1", meta.Source.Name)
8985
}
9086

9187
func TestConfigBuilder_LogLevelFromSecondCollector(t *testing.T) {
9288
t.Parallel()
9389

94-
// Create two map collectors with overlapping keys.
9590
map1 := map[string]any{
9691
"server": map[string]any{
9792
"port": 8080,
@@ -100,7 +95,7 @@ func TestConfigBuilder_LogLevelFromSecondCollector(t *testing.T) {
10095
}
10196
map2 := map[string]any{
10297
"server": map[string]any{
103-
"port": 9090, // Overrides port.
98+
"port": 9090,
10499
},
105100
"log": map[string]any{
106101
"level": "debug",
@@ -116,15 +111,14 @@ func TestConfigBuilder_LogLevelFromSecondCollector(t *testing.T) {
116111
builder = builder.AddCollector(col2)
117112

118113
cfg, errs := builder.Build()
119-
must.SliceEmpty(t, errs)
114+
require.Empty(t, errs)
120115

121-
// Check log level from second collector.
122116
var level string
123117

124118
meta, err := cfg.Get(config.NewKeyPath("log/level"), &level)
125-
must.NoError(t, err)
126-
test.Eq(t, "debug", level)
127-
test.Eq(t, "map2", meta.Source.Name)
119+
require.NoError(t, err)
120+
assert.Equal(t, "debug", level)
121+
assert.Equal(t, "map2", meta.Source.Name)
128122
}
129123

130124
func TestConfigBuilder_Lookup_ExistingKey(t *testing.T) {
@@ -139,14 +133,14 @@ func TestConfigBuilder_Lookup_ExistingKey(t *testing.T) {
139133
builder = builder.AddCollector(col)
140134

141135
cfg, errs := builder.Build()
142-
must.SliceEmpty(t, errs)
136+
require.Empty(t, errs)
143137

144138
val, ok := cfg.Lookup(config.NewKeyPath("foo"))
145-
must.True(t, ok)
139+
require.True(t, ok)
146140

147141
var s string
148-
must.NoError(t, val.Get(&s))
149-
test.Eq(t, "bar", s)
142+
require.NoError(t, val.Get(&s))
143+
assert.Equal(t, "bar", s)
150144
}
151145

152146
func TestConfigBuilder_Lookup_NonExistentKey(t *testing.T) {
@@ -161,9 +155,8 @@ func TestConfigBuilder_Lookup_NonExistentKey(t *testing.T) {
161155
builder = builder.AddCollector(col)
162156

163157
cfg, errs := builder.Build()
164-
must.SliceEmpty(t, errs)
158+
require.Empty(t, errs)
165159

166-
// Non-existent key.
167160
_, ok := cfg.Lookup(config.NewKeyPath("nonexistent"))
168-
must.False(t, ok)
161+
assert.False(t, ok)
169162
}

collectors/env_test.go

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/shoenig/test"
9-
"github.com/shoenig/test/must"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
1010

1111
"github.com/tarantool/go-config"
1212
"github.com/tarantool/go-config/collectors"
@@ -17,39 +17,39 @@ func TestNewEnv(t *testing.T) {
1717
t.Parallel()
1818

1919
ec := collectors.NewEnv()
20-
must.NotNil(t, ec)
21-
test.Eq(t, "env", ec.Name())
22-
test.Eq(t, config.EnvSource, ec.Source())
23-
test.Eq(t, "", ec.Revision())
24-
test.False(t, ec.KeepOrder())
20+
require.NotNil(t, ec)
21+
assert.Equal(t, "env", ec.Name())
22+
assert.Equal(t, config.EnvSource, ec.Source())
23+
assert.Equal(t, config.RevisionType(""), ec.Revision())
24+
assert.False(t, ec.KeepOrder())
2525
}
2626

2727
func TestEnv_WithName(t *testing.T) {
2828
t.Parallel()
2929

3030
ec := collectors.NewEnv().WithName("custom")
31-
test.Eq(t, "custom", ec.Name())
31+
assert.Equal(t, "custom", ec.Name())
3232
}
3333

3434
func TestEnv_WithSourceType(t *testing.T) {
3535
t.Parallel()
3636

3737
ec := collectors.NewEnv().WithSourceType(config.FileSource)
38-
test.Eq(t, config.FileSource, ec.Source())
38+
assert.Equal(t, config.FileSource, ec.Source())
3939
}
4040

4141
func TestEnv_WithRevision(t *testing.T) {
4242
t.Parallel()
4343

4444
ec := collectors.NewEnv().WithRevision("v1.0.0")
45-
test.Eq(t, "v1.0.0", ec.Revision())
45+
assert.Equal(t, config.RevisionType("v1.0.0"), ec.Revision())
4646
}
4747

4848
func TestEnv_WithKeepOrder(t *testing.T) {
4949
t.Parallel()
5050

5151
ec := collectors.NewEnv().WithKeepOrder(true)
52-
test.True(t, ec.KeepOrder())
52+
assert.True(t, ec.KeepOrder())
5353
}
5454

5555
func TestEnv_Read_Basic(t *testing.T) {
@@ -68,14 +68,13 @@ func TestEnv_Read_Basic(t *testing.T) {
6868
values = append(values, val)
6969
}
7070

71-
test.Len(t, 2, values)
71+
assert.Len(t, values, 2)
7272

73-
// Verify values can be extracted.
7473
for _, val := range values {
7574
var dest any
7675

7776
err := val.Get(&dest)
78-
must.NoError(t, err)
77+
require.NoError(t, err)
7978
}
8079
}
8180

@@ -90,15 +89,14 @@ func TestEnv_Read_Transformation(t *testing.T) {
9089
WithDelimiter("_")
9190
ch := ec.Read(ctx)
9291

93-
// Collect values into a map for easier assertion.
9492
got := make(map[string]any)
9593

9694
for val := range ch {
9795
var dest any
9896

9997
err := val.Get(&dest)
100-
must.NoError(t, err)
101-
// Get key path from meta.
98+
require.NoError(t, err)
99+
102100
meta := val.Meta()
103101
key := meta.Key.String()
104102

@@ -109,7 +107,7 @@ func TestEnv_Read_Transformation(t *testing.T) {
109107
"db/host": "localhost",
110108
"db/port": "5432",
111109
}
112-
test.Eq(t, expected, got)
110+
assert.Equal(t, expected, got)
113111
}
114112

115113
func TestEnv_Read_CustomTransform(t *testing.T) {
@@ -118,7 +116,6 @@ func TestEnv_Read_CustomTransform(t *testing.T) {
118116
t.Setenv("MYAPP_FOO_BAR", "value")
119117

120118
transform := func(key string) config.KeyPath {
121-
// Simply split by underscore and reverse order.
122119
parts := strings.Split(key, "_")
123120
for i, j := 0, len(parts)-1; i < j; i, j = i+1, j-1 {
124121
parts[i], parts[j] = parts[j], parts[i]
@@ -138,7 +135,7 @@ func TestEnv_Read_CustomTransform(t *testing.T) {
138135
var dest any
139136

140137
err := val.Get(&dest)
141-
must.NoError(t, err)
138+
require.NoError(t, err)
142139

143140
meta := val.Meta()
144141

@@ -148,7 +145,7 @@ func TestEnv_Read_CustomTransform(t *testing.T) {
148145
expected := map[string]any{
149146
"BAR/FOO": "value",
150147
}
151-
test.Eq(t, expected, got)
148+
assert.Equal(t, expected, got)
152149
}
153150

154151
func TestEnv_Read_Cancellation(t *testing.T) {
@@ -160,16 +157,14 @@ func TestEnv_Read_Cancellation(t *testing.T) {
160157
ec := collectors.NewEnv().WithPrefix("MYAPP_")
161158
valueCh := ec.Read(ctx)
162159

163-
// Read first value.
164160
val, ok := <-valueCh
165-
must.True(t, ok)
161+
require.True(t, ok)
166162

167163
var dest int
168164

169165
err := val.Get(&dest)
170-
must.NoError(t, err)
166+
require.NoError(t, err)
171167

172-
// Cancel context.
173168
cancel()
174169

175170
testutil.Drain(t, valueCh)

0 commit comments

Comments
 (0)