forked from jippi/scm-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Global configuration file (#7)
* feat: Global config support * Config test * Test for includes merging * Linting fix * Linting fix * Unused func * Apply suggestions from code review Co-authored-by: Colin O'Dell <[email protected]> * Code review suggestions --------- Co-authored-by: Colin O'Dell <[email protected]>
- Loading branch information
1 parent
2ee82cc
commit 1a1b515
Showing
9 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package config_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jippi/scm-engine/pkg/config" | ||
"github.com/jippi/scm-engine/pkg/scm" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConfig_Merge(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
cfg *config.Config | ||
other *config.Config | ||
want *config.Config | ||
}{ | ||
{ | ||
name: "merge when other is nil", | ||
cfg: &config.Config{ | ||
DryRun: scm.Ptr(false), | ||
}, | ||
other: nil, | ||
want: &config.Config{ | ||
DryRun: scm.Ptr(false), | ||
}, | ||
}, | ||
{ | ||
name: "override dry run", | ||
cfg: &config.Config{ | ||
DryRun: scm.Ptr(false), | ||
}, | ||
other: &config.Config{ | ||
DryRun: nil, | ||
}, | ||
want: &config.Config{ | ||
DryRun: nil, | ||
}, | ||
}, | ||
{ | ||
name: "merge ignore activity", | ||
cfg: &config.Config{ | ||
IgnoreActivityFrom: config.IgnoreActivityFrom{ | ||
IsBot: false, | ||
Usernames: []string{"user1"}, | ||
Emails: []string{"[email protected]"}, | ||
}, | ||
}, | ||
other: &config.Config{ | ||
IgnoreActivityFrom: config.IgnoreActivityFrom{ | ||
IsBot: true, | ||
Usernames: []string{"user3"}, | ||
Emails: []string{"[email protected]"}, | ||
}, | ||
}, | ||
want: &config.Config{ | ||
IgnoreActivityFrom: config.IgnoreActivityFrom{ | ||
IsBot: true, | ||
Usernames: []string{"user1", "user3"}, | ||
Emails: []string{"[email protected]", "[email protected]"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "merge actions", | ||
cfg: &config.Config{ | ||
Actions: []config.Action{{Name: "action1"}}, | ||
}, | ||
other: &config.Config{ | ||
Actions: []config.Action{{Name: "action2"}}, | ||
}, | ||
want: &config.Config{Actions: []config.Action{{Name: "action1"}, {Name: "action2"}}}, | ||
}, | ||
{ | ||
name: "merge labels", | ||
cfg: &config.Config{Labels: config.Labels{{Name: "label1"}}}, | ||
other: &config.Config{ | ||
Labels: config.Labels{{Name: "label2"}}, | ||
}, | ||
want: &config.Config{Labels: config.Labels{{Name: "label1"}, {Name: "label2"}}}, | ||
}, | ||
{ | ||
name: "merge includes", | ||
cfg: &config.Config{Includes: []config.Include{{Project: "project1", Ref: scm.Ptr("ref1"), Files: []string{"file1"}}}}, | ||
other: &config.Config{ | ||
Includes: []config.Include{{Project: "project1", Ref: scm.Ptr("ref1"), Files: []string{"file2"}}}, | ||
}, | ||
want: &config.Config{ | ||
Includes: []config.Include{ | ||
{Project: "project1", Ref: scm.Ptr("ref1"), Files: []string{"file1"}}, | ||
{Project: "project1", Ref: scm.Ptr("ref1"), Files: []string{"file2"}}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tt.cfg.Merge(tt.other) | ||
require.Equal(t, tt.want, tt.cfg) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters