@@ -9,29 +9,30 @@ import (
99
1010func TestCommitPrefixMigrations (t * testing.T ) {
1111 scenarios := []struct {
12- name string
13- input string
14- expected string
12+ name string
13+ input string
14+ expected string
15+ assertAsString bool
1516 }{
1617 {
17- "Empty String" ,
18- "" ,
19- "" ,
18+ name : "Empty String" ,
19+ input : "" ,
20+ expected : "" ,
2021 }, {
21- "Single CommitPrefix Rename" ,
22- `
22+ name : "Single CommitPrefix Rename" ,
23+ input : `
2324git:
2425 commitPrefix:
2526 pattern: "^\\w+-\\w+.*"
2627 replace: '[JIRA $0] '` ,
27- `
28+ expected : `
2829git:
2930 commitPrefix:
3031 - pattern: "^\\w+-\\w+.*"
3132 replace: '[JIRA $0] '` ,
3233 }, {
33- "Complicated CommitPrefixes Rename" ,
34- `
34+ name : "Complicated CommitPrefixes Rename" ,
35+ input : `
3536git:
3637 commitPrefixes:
3738 foo:
4041 CrazyName!@#$^*&)_-)[[}{f{[]:
4142 pattern: "^foo.bar*"
4243 replace: '[FUN $0] '` ,
43- `
44+ expected : `
4445git:
4546 commitPrefixes:
4647 foo:
5051 - pattern: "^foo.bar*"
5152 replace: '[FUN $0] '` ,
5253 }, {
53- "Incomplete Configuration" ,
54- "git:" ,
55- "git:" ,
54+ name : "Incomplete Configuration" ,
55+ input : "git:" ,
56+ expected : "git:" ,
57+ }, {
58+ name : "No changes made when already migrated" ,
59+ input : `
60+ git:
61+ commitPrefix:
62+ - pattern: "Hello World"
63+ replace: "Goodbye"
64+ commitPrefixes:
65+ foo:
66+ - pattern: "^\\w+-\\w+.*"
67+ replace: '[JIRA $0] '` ,
68+ expected : `
69+ git:
70+ commitPrefix:
71+ - pattern: "Hello World"
72+ replace: "Goodbye"
73+ commitPrefixes:
74+ foo:
75+ - pattern: "^\\w+-\\w+.*"
76+ replace: '[JIRA $0] '` ,
77+ assertAsString : true ,
5678 },
5779 }
5880
6385 if err != nil {
6486 t .Error (err )
6587 }
66- actual , err := computeMigratedConfig ("path doesn't matter" , []byte (s .input ))
88+ actualBytes , err := computeMigratedConfig ("path doesn't matter" , []byte (s .input ))
6789 if err != nil {
6890 t .Error (err )
6991 }
7092 actualConfig := GetDefaultConfig ()
71- err = yaml .Unmarshal (actual , actualConfig )
93+ err = yaml .Unmarshal (actualBytes , actualConfig )
7294 if err != nil {
7395 t .Error (err )
7496 }
75- assert .Equal (t , expectedConfig , actualConfig )
97+
98+ // In most cases, yaml assertion is more robust,
99+ // but in some we are checking for differences in whitespace
100+ if s .assertAsString {
101+ assert .Equal (t , s .expected , string (actualBytes ))
102+ } else {
103+ assert .Equal (t , expectedConfig , actualConfig )
104+ }
76105 })
77106 }
78107}
0 commit comments