git-chglog/processor_test.go
Derek Smith ae3382b7c8
chore(ci): add golangci-lint action and apply linting changes (#120)
BREAKING CHANGE: `JiraIssueId` has been renamed to `JiraIssueID`. This impacts the value for `pattern_maps` in `config.yml`.

* chore(ci): add golangci-lint action

* chore(lint): address errcheck lint failures

* chore(lint): address misspell lint failures

* chore(lint): address gocritic lint failures

* chore(lint): address golint lint failures

* chore(lint): address structcheck lint failures

* chore(lint): address gosimple lint failures

* chore(lint): address gofmt lint failures

* chore(ci): port to official golangci-lint github action

* Update golangci configuration for better coverage

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>

* fix: file is not goimports-ed

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>

* fix: golint and exported functions comments

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>

* chore(lint): address gosec G304 warning

* chore(lint): address uparam warnings

* chore(lint): address scopelint lint failures

* fix: cyclomatic complexity

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>

* chore(lint): address prealloc warning, noting that we are warning for now

* chore(lint): address govet and errorlint failures

* chore: clean up defer logic when checking errors

Co-authored-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-16 21:24:36 -05:00

193 lines
4 KiB
Go

package chglog
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGitHubProcessor(t *testing.T) {
assert := assert.New(t)
config := &Config{
Info: &Info{
RepositoryURL: "https://example.com",
},
}
processor := &GitHubProcessor{}
processor.Bootstrap(config)
assert.Equal(
&Commit{
Header: "message [@foo](https://github.com/foo) [#123](https://example.com/issues/123)",
Subject: "message [@foo](https://github.com/foo) [#123](https://example.com/issues/123)",
Body: `issue [#456](https://example.com/issues/456)
multiline [#789](https://example.com/issues/789)
[@foo](https://github.com/foo), [@bar](https://github.com/bar)`,
Notes: []*Note{
{
Body: `issue1 [#11](https://example.com/issues/11)
issue2 [#22](https://example.com/issues/22)
[gh-56](https://example.com/issues/56) hoge fuga`,
},
},
},
processor.ProcessCommit(
&Commit{
Header: "message @foo #123",
Subject: "message @foo #123",
Body: `issue #456
multiline #789
@foo, @bar`,
Notes: []*Note{
{
Body: `issue1 #11
issue2 #22
gh-56 hoge fuga`,
},
},
},
),
)
assert.Equal(
&Commit{
Revert: &Revert{
Header: "revert header [@mention](https://github.com/mention) [#123](https://example.com/issues/123)",
},
},
processor.ProcessCommit(
&Commit{
Revert: &Revert{
Header: "revert header @mention #123",
},
},
),
)
}
func TestGitLabProcessor(t *testing.T) {
assert := assert.New(t)
config := &Config{
Info: &Info{
RepositoryURL: "https://example.com",
},
}
processor := &GitLabProcessor{}
processor.Bootstrap(config)
assert.Equal(
&Commit{
Header: "message [@foo](https://gitlab.com/foo) [#123](https://example.com/issues/123)",
Subject: "message [@foo](https://gitlab.com/foo) [#123](https://example.com/issues/123)",
Body: `issue [#456](https://example.com/issues/456)
multiline [#789](https://example.com/issues/789)
[@foo](https://gitlab.com/foo), [@bar](https://gitlab.com/bar)`,
Notes: []*Note{
{
Body: `issue1 [#11](https://example.com/issues/11)
issue2 [#22](https://example.com/issues/22)
gh-56 hoge fuga`,
},
},
},
processor.ProcessCommit(
&Commit{
Header: "message @foo #123",
Subject: "message @foo #123",
Body: `issue #456
multiline #789
@foo, @bar`,
Notes: []*Note{
{
Body: `issue1 #11
issue2 #22
gh-56 hoge fuga`,
},
},
},
),
)
assert.Equal(
&Commit{
Revert: &Revert{
Header: "revert header [@mention](https://gitlab.com/mention) [#123](https://example.com/issues/123)",
},
},
processor.ProcessCommit(
&Commit{
Revert: &Revert{
Header: "revert header @mention #123",
},
},
),
)
}
func TestBitbucketProcessor(t *testing.T) {
assert := assert.New(t)
config := &Config{
Info: &Info{
RepositoryURL: "https://example.com",
},
}
processor := &BitbucketProcessor{}
processor.Bootstrap(config)
assert.Equal(
&Commit{
Header: "message [@foo](https://bitbucket.org/foo/) [#123](https://example.com/issues/123/)",
Subject: "message [@foo](https://bitbucket.org/foo/) [#123](https://example.com/issues/123/)",
Body: `issue [#456](https://example.com/issues/456/)
multiline [#789](https://example.com/issues/789/)
[@foo](https://bitbucket.org/foo/), [@bar](https://bitbucket.org/bar/)`,
Notes: []*Note{
{
Body: `issue1 [#11](https://example.com/issues/11/)
issue2 [#22](https://example.com/issues/22/)
gh-56 hoge fuga`,
},
},
},
processor.ProcessCommit(
&Commit{
Header: "message @foo #123",
Subject: "message @foo #123",
Body: `issue #456
multiline #789
@foo, @bar`,
Notes: []*Note{
{
Body: `issue1 #11
issue2 #22
gh-56 hoge fuga`,
},
},
},
),
)
assert.Equal(
&Commit{
Revert: &Revert{
Header: "revert header [@mention](https://bitbucket.org/mention/) [#123](https://example.com/issues/123/)",
},
},
processor.ProcessCommit(
&Commit{
Revert: &Revert{
Header: "revert header @mention #123",
},
},
),
)
}