2019-07-21 15:07:13 +02:00
|
|
|
package analyzer_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/Nightapes/go-semantic-release/internal/analyzer"
|
2019-08-11 18:27:52 +02:00
|
|
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
2019-07-21 15:07:13 +02:00
|
|
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestAngular(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
testConfigs := []struct {
|
|
|
|
|
testCase string
|
2019-08-11 18:27:52 +02:00
|
|
|
commits []shared.Commit
|
|
|
|
|
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
2019-07-21 15:07:13 +02:00
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
testCase: "feat",
|
2019-08-11 18:27:52 +02:00
|
|
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
|
|
|
|
"minor": []shared.AnalyzedCommit{
|
|
|
|
|
shared.AnalyzedCommit{
|
|
|
|
|
Commit: shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
|
|
|
|
Scope: "internal/changelog",
|
|
|
|
|
ParsedMessage: "my first commit",
|
|
|
|
|
Tag: "feat",
|
|
|
|
|
TagString: "Features",
|
|
|
|
|
Print: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
"major": []shared.AnalyzedCommit{},
|
|
|
|
|
"patch": []shared.AnalyzedCommit{},
|
|
|
|
|
"none": []shared.AnalyzedCommit{},
|
2019-07-21 15:07:13 +02:00
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
commits: []shared.Commit{
|
|
|
|
|
shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testCase: "feat breaking change",
|
2019-08-11 18:27:52 +02:00
|
|
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
|
|
|
|
"minor": []shared.AnalyzedCommit{
|
|
|
|
|
shared.AnalyzedCommit{
|
|
|
|
|
Commit: shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
|
|
|
|
Scope: "internal/changelog",
|
|
|
|
|
ParsedMessage: "my first commit",
|
|
|
|
|
Tag: "feat",
|
|
|
|
|
TagString: "Features",
|
|
|
|
|
Print: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
"major": []shared.AnalyzedCommit{
|
|
|
|
|
shared.AnalyzedCommit{
|
|
|
|
|
Commit: shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345668",
|
|
|
|
|
},
|
|
|
|
|
Scope: "internal/changelog",
|
|
|
|
|
ParsedMessage: "my first break",
|
|
|
|
|
Tag: "feat",
|
|
|
|
|
TagString: "Features",
|
|
|
|
|
Print: true,
|
|
|
|
|
ParsedBreakingChangeMessage: "change api to v2",
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
"patch": []shared.AnalyzedCommit{},
|
|
|
|
|
"none": []shared.AnalyzedCommit{},
|
2019-07-21 15:07:13 +02:00
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
commits: []shared.Commit{
|
|
|
|
|
shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345668",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testCase: "invalid",
|
2019-08-11 18:27:52 +02:00
|
|
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
|
|
|
|
"minor": []shared.AnalyzedCommit{},
|
|
|
|
|
"major": []shared.AnalyzedCommit{},
|
|
|
|
|
"patch": []shared.AnalyzedCommit{},
|
|
|
|
|
"none": []shared.AnalyzedCommit{},
|
2019-07-21 15:07:13 +02:00
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
commits: []shared.Commit{
|
|
|
|
|
shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "internal/changelog: my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
2019-08-25 14:16:57 +02:00
|
|
|
shared.Commit{
|
|
|
|
|
Message: "Merge feat(internal/changelog): my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
2019-07-21 15:07:13 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testCase: "feat and build",
|
2019-08-11 18:27:52 +02:00
|
|
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
|
|
|
|
"minor": []shared.AnalyzedCommit{
|
|
|
|
|
shared.AnalyzedCommit{
|
|
|
|
|
Commit: shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
|
|
|
|
Scope: "internal/changelog",
|
|
|
|
|
ParsedMessage: "my first commit",
|
|
|
|
|
Tag: "feat",
|
|
|
|
|
TagString: "Features",
|
|
|
|
|
Print: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
"none": []shared.AnalyzedCommit{
|
|
|
|
|
shared.AnalyzedCommit{
|
|
|
|
|
Commit: shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "build(internal/changelog): my first build",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345668",
|
|
|
|
|
},
|
|
|
|
|
Scope: "internal/changelog",
|
|
|
|
|
ParsedMessage: "my first build",
|
|
|
|
|
Tag: "build",
|
|
|
|
|
TagString: "Changes to CI/CD",
|
|
|
|
|
Print: false,
|
|
|
|
|
ParsedBreakingChangeMessage: "",
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
"patch": []shared.AnalyzedCommit{},
|
|
|
|
|
"major": []shared.AnalyzedCommit{},
|
2019-07-21 15:07:13 +02:00
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
commits: []shared.Commit{
|
|
|
|
|
shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "feat(internal/changelog): my first commit",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345667",
|
|
|
|
|
},
|
2019-08-11 18:27:52 +02:00
|
|
|
shared.Commit{
|
2019-07-21 15:07:13 +02:00
|
|
|
Message: "build(internal/changelog): my first build",
|
|
|
|
|
Author: "me",
|
|
|
|
|
Hash: "12345668",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
angular, err := analyzer.New("angular", config.ChangelogConfig{})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
for _, test := range testConfigs {
|
|
|
|
|
analyzedCommits := angular.Analyze(test.commits)
|
|
|
|
|
assert.Equalf(t, test.analyzedCommits["major"], analyzedCommits["major"], "Testcase %s should have major commits", test.testCase)
|
|
|
|
|
assert.Equalf(t, test.analyzedCommits["minor"], analyzedCommits["minor"], "Testcase %s should have minor commits", test.testCase)
|
|
|
|
|
assert.Equalf(t, test.analyzedCommits["patch"], analyzedCommits["patch"], "Testcase %s should have patch commits", test.testCase)
|
|
|
|
|
assert.Equalf(t, test.analyzedCommits["none"], analyzedCommits["none"], "Testcase %s should have none commits", test.testCase)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|