Skip to content

Commit

Permalink
✅ Parallelise tests
Browse files Browse the repository at this point in the history
Parallelise tests to decrease testing time. Some external packages had
to be excluded as they referencing global variables. These were:

1. github.com/ivanpirog/coloredcobra
2. github.com/go-git/go-git-fixtures

The package providing pseudo tty support has a date race issue that
caused failures rarely. Parallel tests identified that this occurs in
approximately 10% of tests. No changes have been made as this can occur
on the first test attempt.
  • Loading branch information
mikelorant committed Feb 4, 2023
1 parent 30ffbb8 commit 22eb76d
Show file tree
Hide file tree
Showing 29 changed files with 390 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestNewVersionCmd(t *testing.T) {
t.Parallel()

tests := []struct {
name string
}{
Expand All @@ -18,7 +20,11 @@ func TestNewVersionCmd(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

ver := cmd.NewVersionCmd()
var buf bytes.Buffer

Expand Down
12 changes: 12 additions & 0 deletions internal/commit/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func MockCreate(err error) func(file string) (io.WriteCloser, error) {
var errMock = errors.New("error")

func TestConfigure(t *testing.T) {
t.Parallel()

type args struct {
opts commit.Options
cfg config.Config
Expand Down Expand Up @@ -336,7 +338,11 @@ func TestConfigure(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

cfg := MockConfig{
cfg: tt.args.cfg,
loadErr: tt.args.configErr,
Expand Down Expand Up @@ -376,6 +382,8 @@ func TestConfigure(t *testing.T) {
}

func TestApply(t *testing.T) {
t.Parallel()

type args struct {
req *commit.Request
createErr error
Expand Down Expand Up @@ -538,7 +546,11 @@ func TestApply(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

repo := MockRepository{
applyErr: tt.args.applyErr,
}
Expand Down
36 changes: 36 additions & 0 deletions internal/commit/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestMessageToEmoji(t *testing.T) {
t.Parallel()

type want struct {
valid bool
name string
Expand Down Expand Up @@ -67,7 +69,11 @@ func TestMessageToEmoji(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

e := commit.MessageToEmoji(emoji.New(), tt.message)
if !tt.want.valid {
assert.False(t, tt.want.valid)
Expand All @@ -81,6 +87,8 @@ func TestMessageToEmoji(t *testing.T) {
}

func TestMessageToSummary(t *testing.T) {
t.Parallel()

tests := []struct {
name string
message string
Expand Down Expand Up @@ -129,7 +137,11 @@ func TestMessageToSummary(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

s := commit.MessageToSummary(tt.message)
if tt.summary == "" {
assert.Empty(t, s)
Expand All @@ -142,6 +154,8 @@ func TestMessageToSummary(t *testing.T) {
}

func TestMessageToBody(t *testing.T) {
t.Parallel()

tests := []struct {
name string
message string
Expand Down Expand Up @@ -178,7 +192,11 @@ func TestMessageToBody(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

b := commit.MessageToBody(tt.message)
if tt.body == "" {
assert.Empty(t, b)
Expand All @@ -191,6 +209,8 @@ func TestMessageToBody(t *testing.T) {
}

func TestEmojiSummaryToSubject(t *testing.T) {
t.Parallel()

type args struct {
emoji string
summary string
Expand Down Expand Up @@ -222,7 +242,11 @@ func TestEmojiSummaryToSubject(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

s := commit.EmojiSummaryToSubject(tt.args.emoji, tt.args.summary)
if tt.subject == "" {
assert.Empty(t, s)
Expand All @@ -235,6 +259,8 @@ func TestEmojiSummaryToSubject(t *testing.T) {
}

func TestUserToAuthor(t *testing.T) {
t.Parallel()

type args struct {
name string
email string
Expand Down Expand Up @@ -271,7 +297,11 @@ func TestUserToAuthor(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

u := repository.User{
Name: tt.args.name,
Email: tt.args.email,
Expand All @@ -289,6 +319,8 @@ func TestUserToAuthor(t *testing.T) {
}

func TestSortUsersByDefault(t *testing.T) {
t.Parallel()

type args struct {
repositoryUsers []repository.User
configUsers []repository.User
Expand Down Expand Up @@ -484,7 +516,11 @@ func TestSortUsersByDefault(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

us := concatSlice(tt.args.repositoryUsers, tt.args.configUsers)
users := commit.SortUsersByDefault(us...)

Expand Down
6 changes: 6 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
var typeError *yaml.TypeError

func TestConfig(t *testing.T) {
t.Parallel()

tests := []struct {
name string
data string
Expand Down Expand Up @@ -395,7 +397,11 @@ func TestConfig(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

cfg, err := new(config.Config).Load(strings.NewReader(tt.data))
if tt.err != nil {
assert.NotNil(t, err)
Expand Down
36 changes: 36 additions & 0 deletions internal/config/emoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestUnmarshallYAMLEmojiSet(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input string
Expand All @@ -22,7 +24,11 @@ func TestUnmarshallYAMLEmojiSet(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

var got config.EmojiSet

yaml.Unmarshal([]byte(tt.input), &got)
Expand All @@ -32,6 +38,8 @@ func TestUnmarshallYAMLEmojiSet(t *testing.T) {
}

func TestUnmarshallYAMLEmojiSelector(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input string
Expand All @@ -44,7 +52,11 @@ func TestUnmarshallYAMLEmojiSelector(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

var got config.EmojiSelector

yaml.Unmarshal([]byte(tt.input), &got)
Expand All @@ -54,6 +66,8 @@ func TestUnmarshallYAMLEmojiSelector(t *testing.T) {
}

func TestUnmarshallYAMLEmojiType(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input string
Expand All @@ -66,7 +80,11 @@ func TestUnmarshallYAMLEmojiType(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

var got config.EmojiType

yaml.Unmarshal([]byte(tt.input), &got)
Expand All @@ -76,6 +94,8 @@ func TestUnmarshallYAMLEmojiType(t *testing.T) {
}

func TestMarshallYAMLEmojiSet(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input config.EmojiSet
Expand All @@ -89,14 +109,20 @@ func TestMarshallYAMLEmojiSet(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

got, _ := yaml.Marshal(&tt.input)
assert.Equal(t, tt.want, string(got), tt.name)
})
}
}

func TestMarshallYAMLEmojiSelector(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input config.EmojiSelector
Expand All @@ -109,14 +135,20 @@ func TestMarshallYAMLEmojiSelector(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

got, _ := yaml.Marshal(&tt.input)
assert.Equal(t, tt.want, string(got), tt.name)
})
}
}

func TestMarshallYAMLEmojiType(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input config.EmojiType
Expand All @@ -129,7 +161,11 @@ func TestMarshallYAMLEmojiType(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

got, _ := yaml.Marshal(&tt.input)
assert.Equal(t, tt.want, string(got), tt.name)
})
Expand Down
Loading

0 comments on commit 22eb76d

Please sign in to comment.