forked from jerray/publish-docker-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_test.go
87 lines (80 loc) · 1.85 KB
/
build_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
package main
import (
"reflect"
"testing"
)
func Test_build(t *testing.T) {
cases := []struct {
inputs Inputs
expect commandArguments
}{
// default
{
inputs: Inputs{
Dockerfile: "Dockerfile",
Path: ".",
},
expect: commandArguments{"docker", []string{"build", "--file", "Dockerfile", "."}},
},
// change docker file
{
inputs: Inputs{
Dockerfile: "./builds/Dockerfile",
Path: ".",
},
expect: commandArguments{"docker", []string{"build", "--file", "./builds/Dockerfile", "."}},
},
// change build context
{
inputs: Inputs{
Dockerfile: "Dockerfile",
Path: "./builds",
},
expect: commandArguments{"docker", []string{"build", "--file", "Dockerfile", "./builds"}},
},
// with cache
{
inputs: Inputs{
Dockerfile: "Dockerfile",
Path: ".",
Cache: "cached_image:latest",
},
expect: commandArguments{"docker", []string{"build", "--file", "Dockerfile",
"--from-cache", "cached_image:latest",
"."}},
},
// with build args
{
inputs: Inputs{
Dockerfile: "Dockerfile",
Path: ".",
BuildArgs: []string{"USER=root", "GROUP=super"},
},
expect: commandArguments{"docker", []string{"build", "--file", "Dockerfile",
"--build-arg", "USER=root",
"--build-arg", "GROUP=super",
".",
}},
},
// with tags
{
inputs: Inputs{
Dockerfile: "Dockerfile",
Path: ".",
Tags: []string{"image1:latest", "image2:latest"},
},
expect: commandArguments{"docker", []string{"build", "--file", "Dockerfile",
"--tag", "image1:latest",
"--tag", "image2:latest",
".",
}},
},
}
for _, c := range cases {
cmd := &mockCommander{}
_ = build(cmd, c.inputs)
if !reflect.DeepEqual(c.expect, cmd.commands[0]) {
t.Errorf("expect command %v, actual is %v", c.expect, cmd.commands[0])
}
}
}