Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing parse repo config. #5

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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