-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsuggest_test.go
More file actions
65 lines (59 loc) · 1.77 KB
/
Copy pathsuggest_test.go
File metadata and controls
65 lines (59 loc) · 1.77 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
package main
import (
"strings"
"testing"
"github.com/haproxytech/check-commit/v5/junit"
)
func TestCheckSubjectSuggestions(t *testing.T) {
t.Parallel()
c, _ := LoadCommitPolicy("")
suggestionTests := []struct {
name string
subject string
wantContain string // expected substring of the error, "" means no suggestion
}{
{
name: "typo in tag",
subject: "DOCS/MINOR: update build targets and process isolation details in README",
wantContain: "did you mean 'DOC/MINOR'?",
},
{
name: "typo in severity",
subject: "DOC/MINR: update build targets and process isolation details in README",
wantContain: "did you mean 'DOC/MINOR'?",
},
{
name: "lowercase tag",
subject: "doc: update build targets and process isolation details in README",
wantContain: "did you mean 'DOC'?",
},
{
name: "typo in severity-only tag",
subject: "MINR: update build targets and process isolation details in README",
wantContain: "did you mean 'MINOR'?",
},
{
name: "unrelated tag gets no suggestion",
subject: "WRONG: update build targets and process isolation details in README",
wantContain: "",
},
}
for _, tt := range suggestionTests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := c.CheckSubject([]byte(tt.subject), &junit.JunitSuiteDummy{})
if err == nil {
t.Fatalf("CheckSubject() expected error for %q, got nil", tt.subject)
}
if tt.wantContain == "" {
if strings.Contains(err.Error(), "did you mean") {
t.Errorf("CheckSubject() error = %v, want no suggestion", err)
}
return
}
if !strings.Contains(err.Error(), tt.wantContain) {
t.Errorf("CheckSubject() error = %v, want substring %q", err, tt.wantContain)
}
})
}
}