From dfe5a5a506314e08716ccf0ee480256b1d362044 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Date: Wed, 16 Jun 2021 18:11:32 +0000 Subject: [PATCH] test: unit test for filter commits with scope --- internal/changelog/filter_test.go | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 internal/changelog/filter_test.go diff --git a/internal/changelog/filter_test.go b/internal/changelog/filter_test.go new file mode 100644 index 0000000..1afef85 --- /dev/null +++ b/internal/changelog/filter_test.go @@ -0,0 +1,100 @@ +package changelog + +import ( + "testing" + + "github.com/haunt98/changeloguru/internal/convention" + "github.com/stretchr/testify/assert" +) + +func TestFilter(t *testing.T) { + tests := []struct { + name string + commits []convention.Commit + scopes map[string]struct{} + want map[string][]convention.Commit + }{ + { + name: "without scopes", + commits: []convention.Commit{ + { + RawHeader: "feature A", + Type: convention.FeatType, + }, + { + RawHeader: "fix B", + Type: convention.FixType, + }, + { + RawHeader: "build", + Type: convention.BuildType, + }, + }, + want: map[string][]convention.Commit{ + addedType: { + { + RawHeader: "feature A", + Type: convention.FeatType, + }, + }, + fixedType: { + { + RawHeader: "fix B", + Type: convention.FixType, + }, + }, + othersType: { + { + RawHeader: "build", + Type: convention.BuildType, + }, + }, + }, + }, + { + name: "with scopes", + commits: []convention.Commit{ + { + RawHeader: "feature A", + Type: convention.FeatType, + Scope: "A", + }, + { + RawHeader: "fix B", + Type: convention.FixType, + Scope: "B", + }, + { + RawHeader: "build", + Type: convention.BuildType, + }, + }, + scopes: map[string]struct{}{ + "A": {}, + }, + want: map[string][]convention.Commit{ + addedType: { + { + RawHeader: "feature A", + Type: convention.FeatType, + Scope: "A", + }, + }, + fixedType: {}, + othersType: { + { + RawHeader: "build", + Type: convention.BuildType, + }, + }, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + got := filter(tc.commits, tc.scopes) + assert.Equal(t, tc.want, got) + }) + } +}