utils_test.go
1.4 KB
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
package utils
import (
"fmt"
"testing"
)
func Test_DeepCopy(t *testing.T) {
type User1 struct {
Name string
Age int
Address string
}
type User2 struct {
Name string
Age int
Job string
}
var src = User1{Name: "foo", Age: 10, Address: "bar"}
var dst *User2
if err := DeepCopy(&dst, src); err != nil {
t.Fatal(err)
}
if src.Name != dst.Name {
t.Fatal("deep copy fail.")
}
//t.Log(src,"\n",dst)
}
func TestValidVersion(t *testing.T) {
inputs := []struct {
In string
Compare string
Out bool
}{
{In: "0.9.0", Compare: "0.8.0", Out: true},
{In: "0.8.11", Compare: "0.8.0", Out: true},
{In: "0.7.0", Compare: "0.8.0", Out: false},
{In: "0.8.0", Compare: "0.8.0", Out: true},
{In: "0.9", Compare: "0.8.0", Out: true},
{In: "0.10", Compare: "0.8.0", Out: true},
{In: "1.8.0", Compare: "0.8.0", Out: true},
{In: "0.99.0", Compare: "0.8.0", Out: true},
{In: "01.0.0", Compare: "0.8.0", Out: true},
}
for i := range inputs {
input := inputs[i]
if ValidVersion(input.In, input.Compare) != input.Out {
t.Fatal(fmt.Sprintf("valid version fail. input :%v compare:%v want:%v", input.In, input.Compare, input.Out))
}
}
}
func TestMergeMap(t *testing.T) {
to := map[string]interface{}{"1": 1, "2": 2}
from := map[string]interface{}{"3": 3, "4": 4}
t.Log("merge 前:", to)
MergeMap(to, from)
t.Log("merge 后:", to)
}