Skip to content

Commit 7d9dae4

Browse files
test: release rule logic
1 parent 236195c commit 7d9dae4

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

pkg/analyzer/commit_analyzer_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,94 @@ func TestDefaultAnalyzer(t *testing.T) {
112112
})
113113
}
114114
}
115+
116+
func TestReleaseRules(t *testing.T) {
117+
type commits []struct {
118+
RawCommit *semrel.RawCommit
119+
Change *semrel.Change
120+
}
121+
testCases := []struct {
122+
Config map[string]string
123+
Commits commits
124+
}{
125+
{
126+
Config: map[string]string{
127+
"major_release_rules": "feat",
128+
"minor_release_rules": "feat",
129+
"patch_release_rules": "feat",
130+
},
131+
Commits: commits{
132+
{
133+
RawCommit: createRawCommit("a", "feat: new feature"),
134+
Change: &semrel.Change{Major: true, Minor: true, Patch: true},
135+
},
136+
{
137+
RawCommit: createRawCommit("a", "docs: new feature"),
138+
Change: &semrel.Change{Major: false, Minor: false, Patch: false},
139+
},
140+
{
141+
RawCommit: createRawCommit("a", "feat!: new feature"),
142+
Change: &semrel.Change{Major: false, Minor: false, Patch: false},
143+
},
144+
{
145+
RawCommit: createRawCommit("a", "feat(api): new feature"),
146+
Change: &semrel.Change{Major: true, Minor: true, Patch: true},
147+
},
148+
{
149+
RawCommit: createRawCommit("a", "feat(api)!: new feature"),
150+
Change: &semrel.Change{Major: false, Minor: false, Patch: false},
151+
},
152+
},
153+
},
154+
{
155+
Config: map[string]string{
156+
"major_release_rules": "*!",
157+
"minor_release_rules": "feat,chore(deps)",
158+
"patch_release_rules": "fix",
159+
},
160+
Commits: commits{
161+
{
162+
RawCommit: createRawCommit("a", "feat: new feature"),
163+
Change: &semrel.Change{Major: false, Minor: true, Patch: false},
164+
},
165+
{
166+
RawCommit: createRawCommit("a", "docs: new feature"),
167+
Change: &semrel.Change{Major: false, Minor: false, Patch: false},
168+
},
169+
{
170+
RawCommit: createRawCommit("a", "docs!: new feature"),
171+
Change: &semrel.Change{Major: true, Minor: false, Patch: false},
172+
},
173+
{
174+
RawCommit: createRawCommit("a", "chore(deps): update dependencies"),
175+
Change: &semrel.Change{Major: false, Minor: true, Patch: false},
176+
},
177+
{
178+
RawCommit: createRawCommit("a", "chore: cleanup"),
179+
Change: &semrel.Change{Major: false, Minor: false, Patch: false},
180+
},
181+
{
182+
RawCommit: createRawCommit("a", "fix: bug #123"),
183+
Change: &semrel.Change{Major: false, Minor: false, Patch: true},
184+
},
185+
{
186+
RawCommit: createRawCommit("a", "fix!: bug #123"),
187+
Change: &semrel.Change{Major: true, Minor: false, Patch: false},
188+
},
189+
},
190+
},
191+
}
192+
for _, tc := range testCases {
193+
defaultAnalyzer := &DefaultCommitAnalyzer{}
194+
require.NoError(t, defaultAnalyzer.Init(tc.Config))
195+
for _, commit := range tc.Commits {
196+
t.Run(commit.RawCommit.RawMessage, func(t *testing.T) {
197+
analyzedCommit := defaultAnalyzer.analyzeSingleCommit(commit.RawCommit)
198+
require.Equal(t, commit.Change.Major, analyzedCommit.Change.Major, "Major")
199+
require.Equal(t, commit.Change.Minor, analyzedCommit.Change.Minor, "Minor")
200+
require.Equal(t, commit.Change.Patch, analyzedCommit.Change.Patch, "Patch")
201+
})
202+
}
203+
204+
}
205+
}

0 commit comments

Comments
 (0)