-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplugin_test.go
105 lines (97 loc) · 2.51 KB
/
plugin_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
package main
import (
"fmt"
"testing"
"github.com/Sirupsen/logrus"
)
type pickTagsTestSet struct {
description string
tags []string
tagRegex string
result string
err error
}
var pickTagTests = []pickTagsTestSet{
{
description: "No regex - Should return first non-latest tag",
tags: []string{"1.0.1-1499290301.test-branch.1234abcd", "1.0.1", "latest"},
tagRegex: "",
result: "1.0.1-1499290301.test-branch.1234abcd",
err: nil,
},
{
description: "Use semver regex - Should return regex match",
tags: []string{"1.0.1-1499290301.test-branch.1234abcd", "1.0.1", "latest"},
tagRegex: "[0-9]+[.][0-9]+[.][0-9]+$",
result: "1.0.1",
err: nil,
},
{
description: "Latest - Should return blank and error",
tags: []string{"latest"},
tagRegex: "[0-9]+[.][0-9]+[.][0-9]+$",
result: "",
err: fmt.Errorf("No valid tags found"),
},
{
description: "No latest and not regex match - Should return first non latest (only) tag",
tags: []string{"1.0.1-1499290301.test-branch.1234abcd"},
tagRegex: "[0-9]+[.][0-9]+[.][0-9]+$",
result: "1.0.1-1499290301.test-branch.1234abcd",
err: nil,
},
{
description: "No tags provided - Should return blank and error",
tags: []string{},
tagRegex: "[0-9]+[.][0-9]+[.][0-9]+$",
result: "",
err: fmt.Errorf("No valid tags found"),
},
}
func TestPickTags(t *testing.T) {
logrus.SetLevel(logrus.ErrorLevel)
for _, set := range pickTagTests {
t.Log(set.description)
result, err := pickTag(set.tags, set.tagRegex)
if result != set.result {
t.Error(
"For tags", set.tags,
"\nFor tagRegex", set.tagRegex,
"\nexpected result", set.result,
"\nexpected err", set.err,
"\ngot result", result,
"\ngot err", err,
)
}
}
}
type fixNameTestSet struct {
description string
name string
result string
}
var fixNameTests = []fixNameTestSet{
{
description: "Should replace underscores, dots and spaces with a dash",
name: "this_is a weird.name",
result: "this-is-a-weird-name",
},
{
description: "Should replace UPPERCASE with lowercase",
name: "thisIsAWeirdName2Have",
result: "thisisaweirdname2have",
},
}
func TestFixName(t *testing.T) {
for _, set := range fixNameTests {
t.Log(set.description)
result := fixName(set.name)
if result != set.result {
t.Error(
"For name", set.name,
"\nexpected result", set.result,
"\ngot result", result,
)
}
}
}