-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcleaner_test.go
More file actions
82 lines (74 loc) · 2.15 KB
/
cleaner_test.go
File metadata and controls
82 lines (74 loc) · 2.15 KB
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
package cleaner
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestGetDiff(t *testing.T) {
nsList := []v1.Namespace{
{ObjectMeta: metav1.ObjectMeta{Name: "app1"}},
{ObjectMeta: metav1.ObjectMeta{Name: "app2"}},
}
dirList := []string{"app1", "app3"}
diff := getDiff(nsList, dirList)
assert.Equal(t, len(diff), 1, "number of items in the disjunction")
}
func TestDirHasGitSuffix(t *testing.T) {
assert.True(t, dirHasGitSuffix("a.git"), "'a.git' reported no git suffix")
assert.False(t, dirHasGitSuffix("abc"), "'a' reported git suffix")
}
func TestLocalDirs(t *testing.T) {
wd, err := os.Getwd()
assert.Equal(t, err, nil)
pkgDir, err := filepath.Abs(wd + "/..")
assert.Equal(t, err, nil)
lDirs, err := localDirs(pkgDir, func(dir string) bool {
// no directories with any dots in them
return len(strings.Split(dir, ".")) == 1
})
assert.Equal(t, err, nil)
expectedPackages := map[string]int{
"cleaner": 1,
"conf": 1,
"controller": 1,
"git": 1,
"gitreceive": 1,
"healthsrv": 1,
"k8s": 1,
"sshd": 1,
"storage": 1,
"sys": 1,
}
actualPackages := map[string]int{}
for _, lDir := range lDirs {
actualPackages[lDir]++
}
assert.Equal(t, len(actualPackages), len(expectedPackages), "number of packages")
for actualPackageName, actualNum := range actualPackages {
if actualNum != 1 {
t.Errorf("found %d %s packages", actualNum, actualPackageName)
continue
}
expectedNum, ok := expectedPackages[actualPackageName]
if !ok {
t.Errorf("found unexpected package %s", actualPackageName)
continue
}
if actualNum != expectedNum {
t.Errorf("found %d %s packages, expected %d", actualNum, actualPackageName, expectedNum)
continue
}
}
}
func TestStripSuffixes(t *testing.T) {
strs := []string{"a.git", "b.git", "c.git", "d"}
newStrs := stripSuffixes(strs, dotGitSuffix)
assert.Equal(t, len(newStrs), len(strs), "number of strings")
for _, str := range newStrs {
assert.False(t, strings.HasSuffix(str, dotGitSuffix), "string %s has suffix %s", str, dotGitSuffix)
}
}