Skip to content

Commit d514df3

Browse files
authored
Merge pull request #5621 from karlkfi/karl-require-assert
Use require for Error and NoError
2 parents 22ce9c0 + 4386868 commit d514df3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+751
-721
lines changed

api/filters/fieldspec/fieldspec_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
"sigs.k8s.io/kustomize/api/filters/fieldspec"
1314
"sigs.k8s.io/kustomize/api/filters/filtersutil"
1415
"sigs.k8s.io/kustomize/kyaml/kio"
@@ -621,7 +622,7 @@ kind: Pod
621622

622623
t.Run(name, func(t *testing.T) {
623624
err := yaml.Unmarshal([]byte(tc.fieldSpec), &filter.FieldSpec)
624-
assert.NoError(t, err)
625+
require.NoError(t, err)
625626
rw := &kio.ByteReadWriter{
626627
Reader: bytes.NewBufferString(tc.input),
627628
Writer: &bytes.Buffer{},
@@ -635,7 +636,7 @@ kind: Pod
635636
Outputs: []kio.Writer{rw},
636637
}.Execute()
637638

638-
assert.NoError(t, err)
639+
require.NoError(t, err)
639640
assert.Equal(t, tc.expected, fieldPaths)
640641
})
641642
}

api/internal/localizer/localizer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func reportFSysDiff(t *testing.T, fSysExpected filesys.FileSystem, fSysActual fi
144144
actualContent, readErr := fSysActual.ReadFile(path)
145145
require.NoError(t, readErr)
146146
expectedContent, findErr := fSysExpected.ReadFile(path)
147-
assert.NoErrorf(t, findErr, "unexpected file %q", path)
147+
require.NoErrorf(t, findErr, "unexpected file %q", path)
148148
if findErr == nil {
149149
assert.Equal(t, string(expectedContent), string(actualContent))
150150
}

api/internal/plugins/utils/utils_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/stretchr/testify/assert"
1312
"github.com/stretchr/testify/require"
1413
"sigs.k8s.io/kustomize/api/konfig"
1514
"sigs.k8s.io/kustomize/api/provider"
@@ -97,8 +96,8 @@ func TestUpdateResourceOptions(t *testing.T) {
9796
require.NoError(t, err)
9897
}
9998
actual, err := UpdateResourceOptions(in)
100-
assert.NoError(t, err)
101-
assert.NoError(t, expected.ErrorIfNotEqualLists(actual))
99+
require.NoError(t, err)
100+
require.NoError(t, expected.ErrorIfNotEqualLists(actual))
102101
}
103102

104103
func TestUpdateResourceOptionsWithInvalidHashAnnotationValues(t *testing.T) {

api/internal/target/kusttarget_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ metadata:
285285
}
286286
expected.RemoveBuildAnnotations()
287287
expYaml, err := expected.AsYaml()
288-
assert.NoError(t, err)
288+
require.NoError(t, err)
289289

290290
kt := makeKustTargetWithRf(t, th.GetFSys(), "/whatever", pvd)
291-
assert.NoError(t, kt.Load())
291+
require.NoError(t, kt.Load())
292292
actual, err := kt.MakeCustomizedResMap()
293-
assert.NoError(t, err)
293+
require.NoError(t, err)
294294
actual.RemoveBuildAnnotations()
295295
actYaml, err := actual.AsYaml()
296-
assert.NoError(t, err)
296+
require.NoError(t, err)
297297
assert.Equal(t, string(expYaml), string(actYaml))
298298
}
299299

@@ -425,7 +425,7 @@ func TestDuplicateExternalGeneratorsForbidden(t *testing.T) {
425425
configPath: another_config.json
426426
`)
427427
_, err := makeAndLoadKustTarget(t, th.GetFSys(), "/generator").AccumulateTarget()
428-
assert.Error(t, err)
428+
require.Error(t, err)
429429
assert.Contains(t, err.Error(), "may not add resource with an already registered id: ManifestGenerator.v1.generators.example/ManifestGenerator")
430430
}
431431

@@ -454,6 +454,6 @@ func TestDuplicateExternalTransformersForbidden(t *testing.T) {
454454
value: 'fail'
455455
`)
456456
_, err := makeAndLoadKustTarget(t, th.GetFSys(), "/transformer").AccumulateTarget()
457-
assert.Error(t, err)
457+
require.Error(t, err)
458458
assert.Contains(t, err.Error(), "may not add resource with an already registered id: ValueAnnotator.v1.transformers.example.co/notImportantHere")
459459
}

api/krusty/duplicatekeys_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
1112
)
1213

@@ -41,6 +42,6 @@ spec:
4142
`)
4243
m := th.Run(".", th.MakeDefaultOptions())
4344
_, err := m.AsYaml()
44-
assert.Error(t, err)
45+
require.Error(t, err)
4546
assert.Contains(t, err.Error(), "mapping key \"env\" already defined")
4647
}

0 commit comments

Comments
 (0)