Skip to content

Commit 52e6fe5

Browse files
authored
Merge pull request #5 from PackagrIO/configfile
2 parents f72392f + c58fc64 commit 52e6fe5

3 files changed

Lines changed: 45 additions & 20 deletions

File tree

pkg/config/config_test.go

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
package config_test
22

3-
//
4-
//func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T) {
5-
// t.Parallel()
6-
//
7-
// //setup
8-
// defer utils.UnsetEnv("PACKAGR_")()
9-
//
10-
// //test
11-
// testConfig, _ := config.Create()
12-
//
13-
// //assert
14-
// require.Equal(t, "generic", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate package_type with generic default")
15-
// require.Equal(t, "default", testConfig.GetString(config.PACKAGR_SCM), "should populate scm with default")
16-
// require.Equal(t, "patch", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate runner with default")
17-
//}
3+
import (
4+
"github.com/analogj/go-util/utils"
5+
"github.com/packagrio/releasr/pkg/config"
6+
"github.com/stretchr/testify/require"
7+
"path"
8+
"testing"
9+
)
10+
11+
func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T) {
12+
//setup
13+
defer utils.UnsetEnv("PACKAGR_")()
14+
15+
//test
16+
testConfig, _ := config.Create()
17+
18+
//assert
19+
require.Equal(t, "generic", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate package_type with generic default")
20+
require.Equal(t, "default", testConfig.GetString(config.PACKAGR_SCM), "should populate scm with default")
21+
require.Equal(t, "Automated packaging of release by Packagr", testConfig.GetString(config.PACKAGR_VERSION_BUMP_MESSAGE), "should populate bump message with default")
22+
}
23+
24+
func TestConfiguration_ReadConfig(t *testing.T) {
25+
//setup
26+
defer utils.UnsetEnv("PACKAGR_")()
27+
28+
testConfig, _ := config.Create()
29+
testConfig.SetDefault(config.PACKAGR_PACKAGE_TYPE, "generic")
30+
testConfig.SetDefault(config.PACKAGR_SCM, "default")
31+
32+
//test
33+
err := testConfig.ReadConfig(path.Join("testdata", "simple_overrides.yml"))
34+
35+
//assert
36+
require.NoErrorf(t, err, "No error")
37+
require.Equal(t, "golang", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate Package Type from overrides config file")
38+
require.Equal(t, "github", testConfig.GetString(config.PACKAGR_SCM), "should populate SCM from overrides config file")
39+
40+
}
41+
42+
1843
//
1944
//func TestConfiguration_init_EnvVariablesShouldLoadProperly(t *testing.T) {
2045
// //setup
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package_type: 'golang'
2+
scm: 'github'

pkg/pipeline.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ func (p *Pipeline) Start(configData config.Interface) error {
3131
return err
3232
}
3333

34-
//Parse Repo config if present.
35-
if err := p.ParseRepoConfig(); err != nil {
36-
return err
37-
}
38-
3934
if err := p.ValidateTools(); err != nil {
4035
return err
4136
}
@@ -68,6 +63,9 @@ func (p *Pipeline) PipelineInitStep() error {
6863
p.Data.GitParentPath = filepath.Dir(cwdPath)
6964

7065
//assumes that this is a git repository, and version file has already been bumped (using Bumpr)
66+
if err := p.ParseRepoConfig(); err != nil {
67+
return err
68+
}
7169

7270
//Generate a new instance of the engine
7371
engineImpl, eerr := engine.Create(p.Config.GetString("package_type"), p.Data, p.Config, p.Scm)

0 commit comments

Comments
 (0)