Skip to content

Commit 95b1e7c

Browse files
committed
custom to user assertion
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@ovhcloud.com>
1 parent c84b56e commit 95b1e7c

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Venom is a CLI (Command Line Interface) that aims to create, manage and run your
3939
- [Assertions](#assertions)
4040
- [Keywords](#keywords)
4141
- [`Must` keywords](#must-keywords)
42-
- [Custom assertions](#custom-assertions)
42+
- [User assertions](#user-assertions)
4343
- [Using logical operators](#using-logical-operators)
4444
- [Write and run your first test suite](#write-and-run-your-first-test-suite)
4545
- [Export tests report](#export-tests-report)
@@ -696,9 +696,9 @@ Example:
696696
# Remaining steps in this context will not be executed
697697
```
698698

699-
#### Custom assertions
699+
#### User assertions
700700

701-
It is possible to use the [user defined executors syntax](#user-defined-executors) and prefixing your executor name with `Should` to create a new custom assertion keyword.
701+
It is possible to use the [user defined executors syntax](#user-defined-executors) and prefixing your executor name with `Should` to create a new "user assertion" keyword.
702702

703703
Example:
704704
```yml
@@ -712,7 +712,7 @@ steps:
712712

713713
You may also include additional steps like a regular user defined executor.
714714

715-
Custom assertions are executed in an entirely clean context, containing only the following variables:
715+
User assertions are executed in an entirely clean context, containing only the following variables:
716716
- `a`: the left operand
717717
- `b`: the (first) right operand
718718
- `argv`: the rights operands
@@ -723,7 +723,7 @@ input:
723723
test: "{{.argv.argv1}}"
724724
```
725725

726-
To call a registered custom assertions, just use its registered name in the `assertions` array, like any built-in assertion keyword.
726+
To call a registered user assertions, just use its registered name in the `assertions` array, like any built-in assertion keyword.
727727

728728
```yml
729729
# test.yml

assertions/assertions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,8 @@ func getTimeFromString(in interface{}) (time.Time, error) {
15091509
return t, nil
15101510
}
15111511

1512-
// RegisterCustomAssertFunc registers a custom assertion function
1513-
func RegisterCustomAssertFunc(name string, ux AssertFunc) error {
1512+
// RegisterUserAssertFunc registers a user assertion function
1513+
func RegisterUserAssertFunc(name string, ux AssertFunc) error {
15141514
if _, ok := assertMap[name]; ok {
15151515
return errors.Errorf("cannot redefine existing assertion %q", name)
15161516
}

assertions/assertions_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ func TestShouldNotJSONEqual(t *testing.T) {
24392439
}
24402440
}
24412441

2442-
func TestRegisterCustomAssertFunc(t *testing.T) {
2442+
func TestRegisterUserAssertFunc(t *testing.T) {
24432443
var assertFunc AssertFunc
24442444

24452445
tests := []struct {
@@ -2465,9 +2465,9 @@ func TestRegisterCustomAssertFunc(t *testing.T) {
24652465

24662466
for _, tt := range tests {
24672467
t.Run(tt.name, func(t *testing.T) {
2468-
err := RegisterCustomAssertFunc(tt.actual, assertFunc)
2468+
err := RegisterUserAssertFunc(tt.actual, assertFunc)
24692469
if (err != nil) != tt.wantErr {
2470-
t.Errorf("RegisterCustomAssertFunc() error = %v, wantErr %v", err, tt.wantErr)
2470+
t.Errorf("RegisterUserAssertFunc() error = %v, wantErr %v", err, tt.wantErr)
24712471
}
24722472
})
24732473
}

venom.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (v *Venom) registerUserExecutors(ctx context.Context) error {
285285
if strings.HasPrefix(ux.Executor, "Should") {
286286
err = v.registerUserAssertFunc(ctx, ux.Executor)
287287
if err != nil {
288-
return errors.Wrapf(err, "unable to register user executor %q from file %q as custom assertion", ux.Executor, f)
288+
return errors.Wrapf(err, "unable to register user executor %q from file %q as user assertion", ux.Executor, f)
289289
}
290290
}
291291
}
@@ -299,7 +299,7 @@ func (v *Venom) registerUserAssertFunc(ctx context.Context, name string) error {
299299
return errors.Wrapf(err, "unable to load user executor %q", name)
300300
}
301301

302-
err = assertions.RegisterCustomAssertFunc(name, func(actual interface{}, expected ...interface{}) error {
302+
err = assertions.RegisterUserAssertFunc(name, func(actual interface{}, expected ...interface{}) error {
303303
// Prepare a minimal context in which the user executor can be run
304304
// We only need to register the operands in the var set
305305
// as parent contexts will already have been templated
@@ -325,7 +325,7 @@ func (v *Venom) registerUserAssertFunc(ctx context.Context, name string) error {
325325
}
326326
return errors.New(strings.Join(msg, "\n"))
327327
} else if err != nil {
328-
return errors.Wrapf(err, "custom assertion failed during execution")
328+
return errors.Wrapf(err, "user assertion failed during execution")
329329
}
330330

331331
return nil

0 commit comments

Comments
 (0)