diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 7926bf7..4847677 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -1,20 +1,45 @@ package config_test -// -//func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T) { -// t.Parallel() -// -// //setup -// defer utils.UnsetEnv("PACKAGR_")() -// -// //test -// testConfig, _ := config.Create() -// -// //assert -// require.Equal(t, "generic", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate package_type with generic default") -// require.Equal(t, "default", testConfig.GetString(config.PACKAGR_SCM), "should populate scm with default") -// require.Equal(t, "patch", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate runner with default") -//} +import ( + "github.com/analogj/go-util/utils" + "github.com/packagrio/releasr/pkg/config" + "github.com/stretchr/testify/require" + "path" + "testing" +) + +func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T) { + //setup + defer utils.UnsetEnv("PACKAGR_")() + + //test + testConfig, _ := config.Create() + + //assert + require.Equal(t, "generic", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate package_type with generic default") + require.Equal(t, "default", testConfig.GetString(config.PACKAGR_SCM), "should populate scm with default") + require.Equal(t, "Automated packaging of release by Packagr", testConfig.GetString(config.PACKAGR_VERSION_BUMP_MESSAGE), "should populate bump message with default") +} + +func TestConfiguration_ReadConfig(t *testing.T) { + //setup + defer utils.UnsetEnv("PACKAGR_")() + + testConfig, _ := config.Create() + testConfig.SetDefault(config.PACKAGR_PACKAGE_TYPE, "generic") + testConfig.SetDefault(config.PACKAGR_SCM, "default") + + //test + err := testConfig.ReadConfig(path.Join("testdata", "simple_overrides.yml")) + + //assert + require.NoErrorf(t, err, "No error") + require.Equal(t, "golang", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate Package Type from overrides config file") + require.Equal(t, "github", testConfig.GetString(config.PACKAGR_SCM), "should populate SCM from overrides config file") + +} + + // //func TestConfiguration_init_EnvVariablesShouldLoadProperly(t *testing.T) { // //setup diff --git a/pkg/config/testdata/simple_overrides.yml b/pkg/config/testdata/simple_overrides.yml new file mode 100644 index 0000000..b2276de --- /dev/null +++ b/pkg/config/testdata/simple_overrides.yml @@ -0,0 +1,2 @@ +package_type: 'golang' +scm: 'github' \ No newline at end of file diff --git a/pkg/pipeline.go b/pkg/pipeline.go index b63de00..406f4c1 100644 --- a/pkg/pipeline.go +++ b/pkg/pipeline.go @@ -31,11 +31,6 @@ func (p *Pipeline) Start(configData config.Interface) error { return err } - //Parse Repo config if present. - if err := p.ParseRepoConfig(); err != nil { - return err - } - if err := p.ValidateTools(); err != nil { return err } @@ -68,6 +63,9 @@ func (p *Pipeline) PipelineInitStep() error { p.Data.GitParentPath = filepath.Dir(cwdPath) //assumes that this is a git repository, and version file has already been bumped (using Bumpr) + if err := p.ParseRepoConfig(); err != nil { + return err + } //Generate a new instance of the engine engineImpl, eerr := engine.Create(p.Config.GetString("package_type"), p.Data, p.Config, p.Scm)