forked from jerray/publish-docker-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
128 lines (125 loc) · 3.65 KB
/
options_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
package main
import (
"os"
"reflect"
"testing"
)
func TestLoadOptions(t *testing.T) {
type innerCase struct {
name string
env map[string]string
expect *Options
}
cases := []innerCase{
{
name: "default values",
env: map[string]string{
"GITHUB_WORKFLOW": "main",
"GITHUB_ACTION": "action name",
"GITHUB_ACTOR": "actor",
"GITHUB_REPOSITORY": "jerray/publish-docker-action",
"GITHUB_SHA": "3b5ec30992fc35b8dd59716f093bf3166a92925b",
"GITHUB_EVENT_NAME": "push",
"GITHUB_EVENT_PATH": "/",
"GITHUB_REF": "refs/heads/master",
"INPUT_USERNAME": "",
"INPUT_PASSWORD": "",
"INPUT_REGISTRY": "",
"INPUT_REPOSITORY": "",
"INPUT_CACHE": "",
"INPUT_ALLOW_PULL_REQUEST": "false",
"INPUT_AUTO_TAG": "false",
},
expect: &Options{
GitHub: GitHub{
Workflow: "main",
Action: "action name",
Actor: "actor",
Repository: "jerray/publish-docker-action",
Commit: "3b5ec30992fc35b8dd59716f093bf3166a92925b",
EventName: "push",
EventPath: "/",
Ref: "refs/heads/master",
},
Inputs: Inputs{
Username: "",
Password: "",
Registry: "",
Repository: "",
Cache: "",
Dockerfile: "Dockerfile",
Path: ".",
Tags: []string{"latest"},
BuildArgs: nil,
AllowPullRequest: false,
AutoTag: false,
},
},
},
{
name: "specific values",
env: map[string]string{
"GITHUB_WORKFLOW": "my workflow",
"GITHUB_ACTION": "action name",
"GITHUB_ACTOR": "actor",
"GITHUB_REPOSITORY": "jerray/publish-docker-action",
"GITHUB_SHA": "3b5ec30992fc35b8dd59716f093bf3166a92925b",
"GITHUB_EVENT_NAME": "push",
"GITHUB_EVENT_PATH": "/",
"GITHUB_REF": "refs/heads/master",
"INPUT_USERNAME": "jerray",
"INPUT_PASSWORD": "password",
"INPUT_REGISTRY": "docker.pkg.github.com",
"INPUT_REPOSITORY": "",
"INPUT_CACHE": "",
"INPUT_FILE": "./builds/Dockerfile",
"INPUT_PATH": "./builds",
"INPUT_TAGS": "tag1,tag2",
"INPUT_BUILD_ARGS": "X=1,Y=2,Z=3",
"INPUT_ALLOW_PULL_REQUEST": "true",
"INPUT_AUTO_TAG": "true",
},
expect: &Options{
GitHub: GitHub{
Workflow: "my workflow",
Action: "action name",
Actor: "actor",
Repository: "jerray/publish-docker-action",
Commit: "3b5ec30992fc35b8dd59716f093bf3166a92925b",
EventName: "push",
EventPath: "/",
Ref: "refs/heads/master",
},
Inputs: Inputs{
Username: "jerray",
Password: "password",
Registry: "docker.pkg.github.com",
Repository: "",
Cache: "",
Dockerfile: "./builds/Dockerfile",
Path: "./builds",
Tags: []string{"tag1", "tag2"},
BuildArgs: []string{"X=1", "Y=2", "Z=3"},
AllowPullRequest: true,
AutoTag: true,
},
},
},
}
for _, c := range cases {
func(c innerCase) {
t.Run(c.name, func(t *testing.T) {
for k, v := range c.env {
_ = os.Setenv(k, v)
}
opts, _ := LoadOptions()
for k := range c.env {
_ = os.Unsetenv(k)
}
if !reflect.DeepEqual(c.expect, opts) {
t.Errorf("expect options is %#v, actual is %#v", c.expect, opts)
}
})
}(c)
}
}