-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_different_policy_test.go
108 lines (98 loc) · 2.34 KB
/
check_different_policy_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
106
107
108
package main
import (
"fmt"
"testing"
yaml "gopkg.in/yaml.v3"
)
const customConfig = `
---
HelpText: "Please refer to https://github.com/haproxy/haproxy/blob/master/CONTRIBUTING#L632"
PatchScopes:
HAProxy Standard Scope:
- MINOR
- MEDIUM
- MAJOR
- CRITICAL
PatchTypes:
SPECIAL patch:
Values:
- SPEC
HAProxy Standard Patch:
Values:
- BUG
- BUILD
- CLEANUP
- DOC
- LICENSE
- OPTIM
- RELEASE
- REORG
- TEST
- REVERT
Scope: HAProxy Standard Scope
HAProxy Standard Feature Commit:
Values:
- MINOR
- MEDIUM
- MAJOR
- CRITICAL
TagOrder:
- PatchTypes:
- SPECIAL patch
Optional: true
- PatchTypes:
- HAProxy Standard Patch
- HAProxy Standard Feature Commit
`
func LoadCommitPolicyData(config string) (CommitPolicyConfig, error) {
var commitPolicy CommitPolicyConfig
if err := yaml.Unmarshal([]byte(config), &commitPolicy); err != nil {
return CommitPolicyConfig{}, fmt.Errorf("error loading commit policy: %w", err)
}
return commitPolicy, nil
}
func TestDifferentPolicy(t *testing.T) {
t.Parallel()
c, _ := LoadCommitPolicyData(customConfig)
testsSpec := []struct {
name string
subject string
wantErr bool
}{
{
name: "valid type and severity",
subject: "SPEC: BUG/MEDIUM: config: add default location of path to the configuration file",
wantErr: false,
},
{
name: "invalid type RANDOM",
subject: "RANDOM: BUG/MEDIUM: config: add default location of path to the configuration file",
wantErr: true,
},
{
name: "invalid type",
subject: "SPEC: HEHEEEEEE/MEDIUM: config: add default location of path to the configuration file",
wantErr: true,
},
{
name: "invalid severity",
subject: "SPEC: BUG/HEHEEEEEE: config: add default location of path to the configuration file",
wantErr: true,
},
{
name: "no existant aditional type",
subject: "SPEC: BUG/MINOR: CI: config: add default location of path to the configuration file",
wantErr: true,
},
}
testsSpec = append(testsSpec, tests...)
for _, tt := range testsSpec {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if err := c.CheckSubject([]byte(tt.subject)); (err != nil) != tt.wantErr {
t.Errorf("checkSubject() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}