Skip to content

Commit

Permalink
Exclusively use assert package
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Oct 29, 2024
1 parent 0662b84 commit 9aefbaa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
4 changes: 0 additions & 4 deletions libs/dyn/dynassert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,3 @@ func PanicsWithError(t assert.TestingT, errString string, f func(), msgAndArgs .
func NotPanics(t assert.TestingT, f func(), msgAndArgs ...interface{}) bool {
return assert.NotPanics(t, f, msgAndArgs...)
}

func JSONEq(t assert.TestingT, expected string, actual string, msgAndArgs ...interface{}) bool {
return assert.JSONEq(t, expected, actual, msgAndArgs...)
}
9 changes: 6 additions & 3 deletions libs/dyn/jsonsaver/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"testing"

assert "github.com/databricks/cli/libs/dyn/dynassert"
"github.com/stretchr/testify/require"
)

func TestEncoder_marshalNoEscape(t *testing.T) {
out, err := marshalNoEscape("1 < 2")
require.NoError(t, err)
if !assert.NoError(t, err) {
return
}

// Confirm the output.
assert.JSONEq(t, `"1 < 2"`, string(out))

Check failure on line 16 in libs/dyn/jsonsaver/encoder_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 16 in libs/dyn/jsonsaver/encoder_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 16 in libs/dyn/jsonsaver/encoder_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
Expand All @@ -23,7 +24,9 @@ func TestEncoder_marshalNoEscape(t *testing.T) {

func TestEncoder_marshalIndentNoEscape(t *testing.T) {
out, err := marshalIndentNoEscape([]string{"1 < 2", "2 < 3"}, "", " ")
require.NoError(t, err)
if !assert.NoError(t, err) {
return
}

// Confirm the output.
assert.JSONEq(t, `["1 < 2", "2 < 3"]`, string(out))

Check failure on line 32 in libs/dyn/jsonsaver/encoder_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 32 in libs/dyn/jsonsaver/encoder_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 32 in libs/dyn/jsonsaver/encoder_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
Expand Down
47 changes: 28 additions & 19 deletions libs/dyn/jsonsaver/saver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,42 @@ import (
"testing"

"github.com/databricks/cli/libs/dyn"
"github.com/stretchr/testify/require"
assert "github.com/databricks/cli/libs/dyn/dynassert"
)

func TestMarshalString(t *testing.T) {
b, err := Marshal(dyn.V("string"))
require.NoError(t, err)
require.JSONEq(t, `"string"`, string(b))
if assert.NoError(t, err) {
assert.JSONEq(t, `"string"`, string(b))

Check failure on line 13 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 13 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 13 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
}
}

func TestMarshalBool(t *testing.T) {
b, err := Marshal(dyn.V(true))
require.NoError(t, err)
require.JSONEq(t, `true`, string(b))
if assert.NoError(t, err) {
assert.JSONEq(t, `true`, string(b))

Check failure on line 20 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 20 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 20 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
}
}

func TestMarshalInt(t *testing.T) {
b, err := Marshal(dyn.V(42))
require.NoError(t, err)
require.JSONEq(t, `42`, string(b))
if assert.NoError(t, err) {
assert.JSONEq(t, `42`, string(b))

Check failure on line 27 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 27 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 27 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
}
}

func TestMarshalFloat(t *testing.T) {
b, err := Marshal(dyn.V(42.1))
require.NoError(t, err)
require.JSONEq(t, `42.1`, string(b))
if assert.NoError(t, err) {
assert.JSONEq(t, `42.1`, string(b))

Check failure on line 34 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 34 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 34 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
}
}

func TestMarshalTime(t *testing.T) {
b, err := Marshal(dyn.V(dyn.MustTime("2021-01-01T00:00:00Z")))
require.NoError(t, err)
require.JSONEq(t, `"2021-01-01T00:00:00Z"`, string(b))
if assert.NoError(t, err) {
assert.JSONEq(t, `"2021-01-01T00:00:00Z"`, string(b))

Check failure on line 41 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 41 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 41 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
}
}

func TestMarshalMap(t *testing.T) {
Expand All @@ -43,8 +48,9 @@ func TestMarshalMap(t *testing.T) {
m.Set(dyn.V("key2"), dyn.V("value2"))

b, err := Marshal(dyn.V(m))
require.NoError(t, err)
require.JSONEq(t, `{"key1":"value1","key2":"value2"}`, string(b))
if assert.NoError(t, err) {
assert.JSONEq(t, `{"key1":"value1","key2":"value2"}`, string(b))

Check failure on line 52 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq

Check failure on line 52 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq

Check failure on line 52 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq
}
}

func TestMarshalSequence(t *testing.T) {
Expand All @@ -53,8 +59,9 @@ func TestMarshalSequence(t *testing.T) {
s = append(s, dyn.V("value2"))

b, err := Marshal(dyn.V(s))
require.NoError(t, err)
require.JSONEq(t, `["value1","value2"]`, string(b))
if assert.NoError(t, err) {
assert.JSONEq(t, `["value1","value2"]`, string(b))

Check failure on line 63 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: assert.JSONEq (compile)

Check failure on line 63 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: assert.JSONEq (compile)

Check failure on line 63 in libs/dyn/jsonsaver/saver_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: assert.JSONEq (compile)
}
}

func TestMarshalComplex(t *testing.T) {
Expand All @@ -72,13 +79,14 @@ func TestMarshalComplex(t *testing.T) {

// Marshal without indent.
b, err := Marshal(dyn.V(root))
require.NoError(t, err)
require.Equal(t, `{"map1":{"str1":"value1","str2":"value2"},"seq1":["value1","value2"]}`+"\n", string(b))
if assert.NoError(t, err) {
assert.Equal(t, `{"map1":{"str1":"value1","str2":"value2"},"seq1":["value1","value2"]}`+"\n", string(b))
}

// Marshal with indent.
b, err = MarshalIndent(dyn.V(root), "", " ")
require.NoError(t, err)
require.Equal(t, `{
if assert.NoError(t, err) {
assert.Equal(t, `{
"map1": {
"str1": "value1",
"str2": "value2"
Expand All @@ -88,4 +96,5 @@ func TestMarshalComplex(t *testing.T) {
"value2"
]
}`+"\n", string(b))
}
}

0 comments on commit 9aefbaa

Please sign in to comment.