-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: YOUR_NAME <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,754 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package assert_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/wklken/fetch/pkg/assert" | ||
) | ||
|
||
func TestNoError(t *testing.T) { | ||
type args struct { | ||
err error | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "test no error", | ||
args: args{ | ||
err: nil, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "test with error", | ||
args: args{ | ||
err: fmt.Errorf("some error"), | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got, _ := assert.NoError(tt.args.err); got != tt.want { | ||
t.Errorf("NoError() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package assert | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestPrettyLine(t *testing.T) { | ||
type args struct { | ||
s interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want interface{} | ||
}{ | ||
{ | ||
name: "test pretty line with string", | ||
args: args{ | ||
s: "hello\nworld", | ||
}, | ||
want: "hello\\nworld", | ||
}, | ||
{ | ||
name: "test pretty line with array", | ||
args: args{ | ||
s: []int{1, 2, 3}, | ||
}, | ||
want: "[1, 2, 3]", | ||
}, | ||
{ | ||
name: "test pretty line with slice", | ||
args: args{ | ||
s: []string{"hello", "world"}, | ||
}, | ||
want: `["hello", "world"]`, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := prettyLine(tt.args.s); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("PrettyLine() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package assert_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/wklken/fetch/pkg/assert" | ||
) | ||
|
||
func TestLessOrEqual(t *testing.T) { | ||
type args struct { | ||
e1 interface{} | ||
e2 interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
wantErr string | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "test less or equal", | ||
args: args{ | ||
e1: 1, | ||
e2: 2, | ||
}, | ||
want: true, | ||
wantErr: "OK", | ||
}, | ||
{ | ||
name: "test not less or equal", | ||
args: args{ | ||
e1: 2, | ||
e2: 1, | ||
}, | ||
want: false, | ||
wantErr: "less_or_equal | `2` is not less than or equal to `1`", | ||
}, | ||
{ | ||
name: "test different types", | ||
args: args{ | ||
e1: 1, | ||
e2: "1", | ||
}, | ||
want: false, | ||
wantErr: "less or equal error, elements should be the same type", | ||
}, | ||
{ | ||
name: "test uncomparable types", | ||
args: args{ | ||
e1: []int{1, 2, 3}, | ||
e2: []int{1, 2, 3}, | ||
}, | ||
want: false, | ||
wantErr: "Can not compare type `[]int`", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, gotErr := assert.LessOrEqual(tt.args.e1, tt.args.e2) | ||
if got != tt.want { | ||
t.Errorf("LessOrEqual() got = %v, want %v", got, tt.want) | ||
} | ||
if gotErr != tt.wantErr { | ||
t.Errorf("LessOrEqual() gotErr = %v, want %v", gotErr, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package assert_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/wklken/fetch/pkg/assert" | ||
) | ||
|
||
func TestEqual(t *testing.T) { | ||
type args struct { | ||
actual interface{} | ||
expected interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "test equal", | ||
args: args{ | ||
actual: 1, | ||
expected: 1, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "test not equal", | ||
args: args{ | ||
actual: 1, | ||
expected: 2, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got, _ := assert.Equal(tt.args.actual, tt.args.expected); got != tt.want { | ||
t.Errorf("Equal() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.