-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoshipdone_test.go
59 lines (55 loc) · 1.33 KB
/
goshipdone_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
// Package goshipdone provides an extendable, build-to-publish pipeline for multiple
// OS-Architecture targets for go packages, built for magefile.
package goshipdone
import (
"os"
"testing"
"github.com/spf13/afero"
)
func Test_detectFilename(t *testing.T) {
tests := []struct {
name string
env string
input string
files []string
want string
}{
{name: "only env", env: "a", input: "", want: "a"},
{name: "only input", env: "", input: "b", want: "b"},
{name: "both env and input", env: "a", input: "b", want: "b"},
{
name: "local file exists",
env: "",
input: "",
files: []string{".goshipdone.local.yml"},
want: ".goshipdone.local.yml",
},
{
name: "local file doesn't exists",
env: "",
input: "",
files: []string{},
want: ".goshipdone.yml",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if tt.env != "" {
os.Setenv("GOSHIPDONE_CONFIG", tt.env)
}
origFS := defaultFS
defaultFS = afero.NewMemMapFs()
for _, filename := range tt.files {
_ = afero.WriteFile(defaultFS, filename, []byte(filename), 0o644)
}
if got := detectFilename(tt.input); got != tt.want {
t.Errorf("detectFilename() = %q, want %q", got, tt.want)
}
defaultFS = origFS
if tt.env != "" {
os.Unsetenv("GOSHIPDONE_CONFIG")
}
})
}
}