Skip to content

Commit

Permalink
test: 💍 unittests (#68)
Browse files Browse the repository at this point in the history
Co-authored-by: YOUR_NAME <[email protected]>
  • Loading branch information
wklken and YOUR_NAME authored Dec 16, 2023
1 parent f4c7ad1 commit cfa1ad5
Show file tree
Hide file tree
Showing 22 changed files with 1,754 additions and 40 deletions.
42 changes: 42 additions & 0 deletions pkg/assert/error_test.go
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)
}
})
}
}
46 changes: 46 additions & 0 deletions pkg/assert/init_test.go
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)
}
})
}
}
69 changes: 69 additions & 0 deletions pkg/assert/numberic_test.go
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)
}
})
}
}
44 changes: 44 additions & 0 deletions pkg/assert/object_test.go
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)
}
})
}
}
Loading

0 comments on commit cfa1ad5

Please sign in to comment.