Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 💍 unittests #68

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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