Skip to content

Commit

Permalink
Merge pull request #3 from PackagrIO/multiple-files
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ authored Nov 17, 2022
2 parents 4ce4992 + 7c26e1e commit 02ce51c
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 109 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cat pkg/version/version.go
- `version_bump_type`
- `version_metadata_path`
- `generic_version_template`
- `addl_version_metadata_paths`

# Outputs
- `release_version`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/packagrio/bumpr

go 1.13
go 1.18

require (
github.com/Masterminds/semver v1.5.0
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (c *configuration) Init() error {
c.SetDefault(PACKAGR_SCM, "default")
c.SetDefault(PACKAGR_VERSION_BUMP_TYPE, "patch")
c.SetDefault(PACKAGR_ENGINE_REPO_CONFIG_PATH, "packagr.yml")
c.SetDefault(PACKAGR_ADDL_VERSION_METADATA_PATHS, map[string]string{})

//set the default system config file search path.
//if you want to load a non-standard location system config file (~/capsule.yml), use ReadConfig
Expand Down
22 changes: 22 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T)
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")
require.Equal(t, map[string]interface{}{}, testConfig.GetStringMap(config.PACKAGR_ADDL_VERSION_METADATA_PATHS), "should populate addl metadata paths from config file")

}

func TestConfiguration_init_EnvVariablesShouldLoadProperly(t *testing.T) {
Expand Down Expand Up @@ -55,3 +57,23 @@ func TestConfiguration_ReadConfig(t *testing.T) {
require.Equal(t, "major", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate Engine Version Bump Type from overrides config file")

}

func TestConfiguration_ReadConfig_AddlVersionMetadataPaths(t *testing.T) {
//setup
defer utils.UnsetEnv("PACKAGR_")()
testConfig, _ := config.Create()
testConfig.SetDefault(config.PACKAGR_PACKAGE_TYPE, "generic")
testConfig.SetDefault(config.PACKAGR_SCM, "default")
testConfig.SetDefault(config.PACKAGR_VERSION_BUMP_TYPE, "patch")

//test
err := testConfig.ReadConfig(path.Join("testdata", "addl_version_metadata_paths.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")
require.Equal(t, "major", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate Engine Version Bump Type from overrides config file")
require.Equal(t, map[string]interface{}{"node": []interface{}{"package.json"}}, testConfig.GetStringMap(config.PACKAGR_ADDL_VERSION_METADATA_PATHS), "should populate addl metadata paths from config file")

}
3 changes: 3 additions & 0 deletions pkg/config/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Interface interface {
GetInt(key string) int
GetString(key string) string
GetStringSlice(key string) []string
GetStringMapString(key string) map[string]string
GetStringMap(key string) map[string]interface{}
UnmarshalKey(key string, rawVal interface{}, decoder ...viper.DecoderConfigOption) error
ReadConfig(configFilePath string) error
}
Expand All @@ -25,5 +27,6 @@ const PACKAGR_PACKAGE_TYPE = "package_type"
const PACKAGR_SCM = "scm"
const PACKAGR_VERSION_BUMP_TYPE = "version_bump_type"
const PACKAGR_VERSION_METADATA_PATH = "version_metadata_path"
const PACKAGR_ADDL_VERSION_METADATA_PATHS = "addl_version_metadata_paths"
const PACKAGR_ENGINE_REPO_CONFIG_PATH = "engine_repo_config_path"
const PACKAGR_GENERIC_VERSION_TEMPLATE = "generic_version_template"
208 changes: 124 additions & 84 deletions pkg/config/mock/mock_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/config/testdata/addl_version_metadata_paths.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package_type: 'golang'
scm: 'github'
version_bump_type: 'major'
addl_version_metadata_paths:
node:
- 'package.json'
Loading

0 comments on commit 02ce51c

Please sign in to comment.