diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 6d4aee4..847f219 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -4,6 +4,7 @@ import ( "github.com/analogj/go-util/utils" "github.com/packagrio/publishr/pkg/config" "github.com/stretchr/testify/require" + "path" "testing" ) @@ -21,6 +22,24 @@ func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T) require.Equal(t, "default", testConfig.GetString(config.PACKAGR_SCM), "should populate scm 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 // os.Setenv("PACKAGR_VERSION_BUMP_TYPE", "major") diff --git a/pkg/config/testdata/simple_overrides.yml b/pkg/config/testdata/simple_overrides.yml new file mode 100644 index 0000000..1ee8806 --- /dev/null +++ b/pkg/config/testdata/simple_overrides.yml @@ -0,0 +1,3 @@ +package_type: 'golang' +scm: 'github' +version_bump_type: 'major' \ No newline at end of file diff --git a/pkg/pipeline.go b/pkg/pipeline.go index f6a1ca7..8673447 100644 --- a/pkg/pipeline.go +++ b/pkg/pipeline.go @@ -12,6 +12,8 @@ import ( "github.com/packagrio/publishr/pkg/mgr" "log" "path" + "os" + "path/filepath" ) type Pipeline struct { @@ -27,10 +29,6 @@ func (p *Pipeline) Start(config config.Interface) error { p.Config = config p.Data = new(pipeline.Data) - if err := p.ParseRepoConfig(); err != nil { - return err - } - if err := p.PipelineInitStep(); err != nil { return err } @@ -45,10 +43,6 @@ func (p *Pipeline) Start(config config.Interface) error { return perr } - if err := p.ParseRepoConfig(); err != nil { - return err - } - if err := p.ValidateTools(); err != nil { return err } @@ -83,6 +77,15 @@ func (p *Pipeline) Start(config config.Interface) error { func (p *Pipeline) PipelineInitStep() error { // start the source, and whatever work needs to be done there. // MUST set options.GitParentPath + cwdPath, _ := os.Getwd() + p.Data.GitLocalPath = cwdPath + p.Data.GitParentPath = filepath.Dir(cwdPath) + + if err := p.ParseRepoConfig(); err != nil { + return err + } + + log.Println("pipeline_init_step") scmImpl, serr := scm.Create(p.Config.GetString(config.PACKAGR_SCM), p.Data, p.Config, nil) if serr != nil {