-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabels_test.go
60 lines (50 loc) · 1.16 KB
/
labels_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
package main
import (
"fmt"
"github.com/spf13/afero"
"testing"
)
const (
testLabelFile = "testLabel"
dependentLabel = "dependentLabel"
)
var (
testLabelPath = fmt.Sprintf("%s/%s", labelDir, testLabelFile)
)
// Create a mocked label in a bare memory-mapped filesystem in order to validate label extraction and matching
func init() {
appfs = afero.NewMemMapFs()
fsutil = &afero.Afero{Fs: appfs}
appfs.MkdirAll(labelDir, 0755)
afero.WriteFile(appfs, testLabelPath, []byte(dependentLabel+"\n"), 0644)
}
func TestReadLabelsFromFile(t *testing.T) {
labels := readLabelsFromFile(testLabelPath)
matched := false
for _, label := range labels {
if label == dependentLabel {
matched = true
break
}
}
if matched == false {
t.Error("unexpected error matching test label")
}
}
func TestBuildLabelMap(t *testing.T) {
labelMap, err := buildPossibleLabelMap()
if err != nil {
t.Error("unexpected error:", err.Error())
return
}
if len(labelMap) == 0 {
t.Error("received an empty label map")
return
}
}
func TestPathToLabel(t *testing.T) {
label := pathToLabel(testLabelPath)
if label != testLabelFile {
t.Errorf("unexpected label: %s\n", label)
}
}