forked from hashicorp/levant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles_test.go
86 lines (70 loc) · 1.59 KB
/
files_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package helper
import (
"io/ioutil"
"os"
"reflect"
"testing"
)
func TestHelper_GetDefaultTmplFile(t *testing.T) {
d1 := []byte("Levant Test Job File\n")
cases := []struct {
TmplFiles []string
Output string
}{
{
[]string{"example.nomad", "example1.nomad"},
"",
},
{
[]string{"example.nomad"},
"example.nomad",
},
}
for _, tc := range cases {
for _, f := range tc.TmplFiles {
// Use write file as tmpfile adds a prefix which doesn't work with the
// GetDefaultTmplFile function.
err := ioutil.WriteFile(f, d1, 0600)
if err != nil {
t.Fatal(err)
}
}
actual := GetDefaultTmplFile()
// Call explicit Remove as the function is dependant on the number of files
// in the target directory.
for _, f := range tc.TmplFiles {
os.Remove(f)
}
if !reflect.DeepEqual(actual, tc.Output) {
t.Fatalf("got: %#v, expected %#v", actual, tc.Output)
}
}
}
func TestHelper_GetDefaultVarFile(t *testing.T) {
d1 := []byte("Levant Test Variable File\n")
cases := []struct {
VarFile string
}{
{"levant.yaml"},
{"levant.yml"},
{"levant.tf"},
{""},
}
for _, tc := range cases {
if tc.VarFile != "" {
// Use write file as tmpfile adds a prefix which doesn't work with the
// GetDefaultTmplFile function.
err := ioutil.WriteFile(tc.VarFile, d1, 0600)
if err != nil {
t.Fatal(err)
}
}
actual := GetDefaultVarFile()
if !reflect.DeepEqual(actual, tc.VarFile) {
t.Fatalf("got: %#v, expected %#v", actual, tc.VarFile)
}
os.Remove(tc.VarFile)
}
}