This repository was archived by the owner on Nov 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathalias_test.go
More file actions
125 lines (111 loc) · 2.84 KB
/
alias_test.go
File metadata and controls
125 lines (111 loc) · 2.84 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package dreck
import (
"fmt"
"testing"
)
func TestAlias(t *testing.T) {
alias := "/plugin (.*) -> /label plugin/$1"
r, err := NewAlias(alias)
if err != nil {
t.Errorf("Failed to parse %s: %v", alias, err)
}
input := "/plugin example"
exp := r.Expand(input)
if exp == input {
t.Errorf("Failed to expand %s", input)
}
t.Logf("Got %s\n", exp)
}
func TestAliasSingle(t *testing.T) {
alias := "/approve -> /lgtm"
r, err := NewAlias(alias)
if err != nil {
t.Errorf("Failed to parse %s: %v", alias, err)
}
input := "/approve"
exp := r.Expand(input)
if exp == input {
t.Errorf("Failed to expand %s", input)
}
t.Logf("Got %s\n", exp)
}
func TestAliasParse(t *testing.T) {
alias := "/plugin (.*) - /label plugin/$1"
if _, err := NewAlias(alias); err == nil {
t.Errorf("Expected to not parse %s", alias)
}
alias = "/plugin (*) - /label plugin/$1"
if _, err := NewAlias(alias); err == nil {
t.Errorf("Expected to not parse %s", alias)
}
}
func TestParsingAlias(t *testing.T) {
conf := &DreckConfig{
Features: []string{Aliases},
Aliases: []string{
fmt.Sprintf("%splugin (.*) -> %slabel plugin/$1", Trigger, Trigger),
fmt.Sprintf("%splugin2 (.*) -> %slabel plugin/$2", Trigger, Trigger),
fmt.Sprintf("%slooksOK -> %slgtm", Trigger, Trigger),
},
}
var options = []struct {
title string
body string
expectedType string
expectedVal string
}{
{
title: "Alias Add label of demo",
body: Trigger + "plugin demo",
expectedType: "AddLabel",
expectedVal: "plugin/demo",
},
{
title: "Alias2 Add label of demo",
body: Trigger + "plugin2 demo",
expectedType: "AddLabel",
expectedVal: "plugin/",
},
{
title: "Alias Add label of demo",
body: Trigger + "plugin demo",
expectedType: "AddLabel",
expectedVal: "plugin/demo",
},
{
title: "Alias Add label of demo case",
body: Trigger + "plUGin demo",
expectedType: "AddLabel",
expectedVal: "plugin/demo",
},
{
title: "Non alias label of demo",
body: Trigger + "pluginner demo",
expectedType: "",
expectedVal: "",
},
{
title: "Lgtm",
body: Trigger + "looksOK",
expectedType: "lgtm",
expectedVal: "",
},
}
for _, test := range options {
t.Run(test.title, func(t *testing.T) {
actions := parse(test.body, conf)
if len(actions) == 0 && test.expectedType == "" { // Ugly hack to should be cleaned up (miek)
// correct, we didn't parse anything
return
}
if len(actions) != 1 {
t.Errorf("Action - not parsed correctly")
return
}
action := actions[0]
if action.Type != test.expectedType || action.Value != test.expectedVal {
t.Errorf("Action - wanted: %s, got %s\nLabel - wanted: %s, got %s", test.expectedType, action.Type, test.expectedVal, action.Value)
}
})
}
}