-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
- Loading branch information
1 parent
59491c9
commit 2ff5635
Showing
5 changed files
with
133 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,67 @@ | ||
package assert | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
// import ( | ||
// "context" | ||
// "testing" | ||
|
||
"github.com/jmespath-community/go-jmespath/pkg/binding" | ||
tassert "github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
) | ||
// "github.com/jmespath-community/go-jmespath/pkg/binding" | ||
// tassert "github.com/stretchr/testify/assert" | ||
// "k8s.io/apimachinery/pkg/util/validation/field" | ||
// ) | ||
|
||
func TestAssert(t *testing.T) { | ||
type args struct { | ||
assertion Assertion | ||
value any | ||
bindings binding.Bindings | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want field.ErrorList | ||
wantErr bool | ||
}{{ | ||
name: "nil vs empty object", | ||
args: args{ | ||
assertion: Parse(context.TODO(), map[string]any{ | ||
"foo": map[string]any{}, | ||
}), | ||
value: map[string]any{ | ||
"foo": nil, | ||
}, | ||
}, | ||
want: field.ErrorList{ | ||
&field.Error{ | ||
Type: field.ErrorTypeInvalid, | ||
Field: "foo", | ||
Detail: "invalid value, must not be null", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, { | ||
name: "not nil vs empty object", | ||
args: args{ | ||
assertion: Parse(context.TODO(), map[string]any{ | ||
"foo": map[string]any{}, | ||
}), | ||
value: map[string]any{ | ||
"foo": map[string]any{ | ||
"bar": 42, | ||
}, | ||
}, | ||
}, | ||
want: nil, | ||
wantErr: false, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := Assert(context.TODO(), nil, tt.args.assertion, tt.args.value, tt.args.bindings) | ||
if tt.wantErr { | ||
tassert.Error(t, err) | ||
} else { | ||
tassert.NoError(t, err) | ||
} | ||
tassert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} | ||
// func TestAssert(t *testing.T) { | ||
// type args struct { | ||
// assertion Assertion | ||
// value any | ||
// bindings binding.Bindings | ||
// } | ||
// tests := []struct { | ||
// name string | ||
// args args | ||
// want field.ErrorList | ||
// wantErr bool | ||
// }{{ | ||
// name: "nil vs empty object", | ||
// args: args{ | ||
// assertion: Parse(context.TODO(), map[string]any{ | ||
// "foo": map[string]any{}, | ||
// }), | ||
// value: map[string]any{ | ||
// "foo": nil, | ||
// }, | ||
// }, | ||
// want: field.ErrorList{ | ||
// &field.Error{ | ||
// Type: field.ErrorTypeInvalid, | ||
// Field: "foo", | ||
// Detail: "invalid value, must not be null", | ||
// }, | ||
// }, | ||
// wantErr: false, | ||
// }, { | ||
// name: "not nil vs empty object", | ||
// args: args{ | ||
// assertion: Parse(context.TODO(), map[string]any{ | ||
// "foo": map[string]any{}, | ||
// }), | ||
// value: map[string]any{ | ||
// "foo": map[string]any{ | ||
// "bar": 42, | ||
// }, | ||
// }, | ||
// }, | ||
// want: nil, | ||
// wantErr: false, | ||
// }} | ||
// for _, tt := range tests { | ||
// t.Run(tt.name, func(t *testing.T) { | ||
// got, err := Assert(context.TODO(), nil, tt.args.assertion, tt.args.value, tt.args.bindings) | ||
// if tt.wantErr { | ||
// tassert.Error(t, err) | ||
// } else { | ||
// tassert.NoError(t, err) | ||
// } | ||
// tassert.Equal(t, tt.want, got) | ||
// }) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters