-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_test.go
65 lines (62 loc) · 1.49 KB
/
process_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
package main
import (
"fmt"
"testing"
)
func TestGetLabelFromNamespace(t *testing.T) {
labelsConfiguration := `
labels:
- caseNamespace: "^([^-]+)-([^-]+)-([^-]+)-([^-]+)$"
inject:
- name: "region"
value: "reg-{{index . 0}}"
- name: area
value: "{{index . 1}}"
- name: team
value: "{{index . 2}}"
- name: environment
value: "{{index . 3}}"
- caseNamespace: "^([^-]+)-([^-]+)-([^-]+)$"
inject:
- name: region
value: "reg-{{index . 0}}"
- name: area
value: "{{index . 1}}"
- name: team
value: "{{index . 2}}"
- name: environment
value: "prod"
- caseNamespace: "^([^-]+)-([^-]+)$"
inject:
- name: region
value: "reg-{{index . 0}}"
- name: system
value: "sys-{{index . 1}}"
`
config, err := NewConfig([]byte(labelsConfiguration))
if err != nil {
fmt.Printf("ERROR: %e", err)
}
for _, i := range []struct {
Namespace string
ExpectedLabels string
}{
{
"region1-area1-team1-environment1",
"map[area:area1 environment:environment1 region:reg-region1 team:team1]",
},
{
"area1-team1-environment1",
"map[area:team1 environment:prod region:reg-area1 team:environment1]",
},
{
"region1-system1",
"map[region:reg-region1 system:sys-system1]",
},
} {
gotLabels := processNamespace(i.Namespace, config.Labels)
if fmt.Sprintf("%+v", gotLabels) != i.ExpectedLabels {
t.Errorf("\nexpected %#v, got %#v", i.ExpectedLabels, fmt.Sprintf("%v", gotLabels))
}
}
}