-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
147 lines (125 loc) · 2.84 KB
/
main_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"fmt"
"net/url"
"os"
"reflect"
"strings"
"testing"
"github.com/techmesh/dotam/conf"
"github.com/techmesh/dotam/util"
docker "github.com/fsouza/go-dockerclient"
"github.com/hashicorp/hcl"
"gopkg.in/yaml.v2"
)
type Account struct {
Name string
}
func TestParseHcl(t *testing.T) {
// bytesTest := []byte(`name = "foo"`)
a := Account{}
o := Account{Name: "tom"}
// b := Account{}
if hcl.Decode(&a, `name = "tom"`); a != o {
t.Fail()
}
}
func TestExist(t *testing.T) {
files := []string{"main.go", "Dotamfile.hcl", "Dotamfile.jon"}
expects := []bool{true, true, false}
results := []bool{}
for _, f := range files {
results = append(results, util.Exist(f))
}
if !reflect.DeepEqual(expects, results) {
t.Fail()
}
}
func TestParseYaml(t *testing.T) {
// data := map[string]interface{}{}
c := conf.DotamConf{}
file := util.ReadFile("Dotamfile.yml")
err := yaml.Unmarshal(file, &c)
if err != nil {
fmt.Println(err)
t.Fail()
}
}
func TestParseArgs(t *testing.T) {
data := []string{"Dotamfile.hcl", "reg_user=tom", "reg_pass=foo"}
data2 := []string{"reg_user=tom", "foo=bar"}
f, a := util.ParseBuildArgs(data)
if !reflect.DeepEqual([]string{"reg_user=tom", "reg_pass=foo"}, a) {
t.Log(a)
t.Fail()
}
if f != "Dotamfile.hcl" {
t.Log(f)
t.Fail()
}
f2, a2 := util.ParseBuildArgs(data2)
if !reflect.DeepEqual([]string{"reg_user=tom", "foo=bar"}, a2) {
t.Log(a2)
t.Fail()
}
if f2 != "" {
t.Log(f2)
t.Fail()
}
}
func TestBuildDockerImage(t *testing.T) {
c, err := docker.NewClientFromEnv()
if err != nil {
// log.Error("current env doesn't support docker, pls check your docker installation")
panic(err)
}
// var buf bytes.Buffer
// dockerfile, err := filepath.Abs("Dockerfile")
if err = c.BuildImage(docker.BuildImageOptions{
Name: "dotam",
ContextDir: ".",
Dockerfile: "Dockerfile",
RmTmpContainer: true,
ForceRmTmpContainer: true,
// Remote: "https://reg.yunpro.cn",
SuppressOutput: false,
// InputStream: &buf,
OutputStream: os.Stdout,
}); err != nil {
panic(err)
}
// log.Debug(DockerClient)
}
func TestParseBuildArgs(t *testing.T) {
args := []string{"reg=foo", "pass=bar"}
qs := strings.Join(args, "&")
data, err := url.ParseQuery(qs)
if err != nil {
t.Log(err)
t.Fail()
}
fmt.Println(data)
}
func TestPushImage(t *testing.T) {
c, err := docker.NewClientFromEnv()
if err != nil {
// log.Error("current env doesn't support docker, pls check your docker installation")
panic(err)
}
d := conf.Docker{
Repo: "dhub.yiliang.cn/adpro/g1-gdt-ios-stupidball",
Tag: "latest",
//Dockerfile: "",
//BuildArgs: nil,
Auth: conf.Auth{
//Username: "abc",
//Password: "bcd",
},
NotPrivate: true,
//Caporal: conf.Caporal{},
}
if err := util.PushImage(d, c); err != nil {
t.Log(err)
t.Fail()
}
}