-
Notifications
You must be signed in to change notification settings - Fork 289
/
car_test.go
85 lines (78 loc) · 1.35 KB
/
car_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package car
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Simple testing what different between Fatal and Error
func TestNew(t *testing.T) {
c, err := New("", 100)
if err != nil {
t.Fatal("got errors:", err)
}
if c == nil {
t.Error("car shoud be nil")
}
}
// Simple testing with testify tool
func TestNewWithAssert(t *testing.T) {
c, err := New("", 100)
assert.NotNil(t, err)
assert.Error(t, err)
assert.Nil(t, c)
c, err = New("foo", 100)
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, c)
assert.Equal(t, "foo", c.Name)
}
func TestCar_SetName(t *testing.T) {
type fields struct {
Name string
Price float32
}
type args struct {
name string
}
tests := []struct {
name string
fields fields
args args
want string
}{
{
name: "no input name",
fields: fields{
Name: "foo",
Price: 100,
},
args: args{
name: "",
},
want: "foo",
},
{
name: "input name",
fields: fields{
Name: "foo",
Price: 100,
},
args: args{
name: "bar",
},
want: "bar",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := &Car{
Name: tt.fields.Name,
Price: tt.fields.Price,
}
if got := c.SetName(tt.args.name); got != tt.want {
t.Errorf("Car.SetName() = %v, want %v", got, tt.want)
}
})
}
}