Skip to content

Commit

Permalink
Merge pull request #5 from PackagrIO/configfile
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ authored Mar 17, 2022
2 parents f72392f + c58fc64 commit 52e6fe5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
55 changes: 40 additions & 15 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/testdata/simple_overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package_type: 'golang'
scm: 'github'
8 changes: 3 additions & 5 deletions pkg/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 52e6fe5

Please sign in to comment.