1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Remove redundancy: no duplicate stepName (#998)

* Remove redundancy: no duplicate stepName

Up to now: provided explicity via command line argument and also contained in the
step metadata (which are as a file also provided as command line argument).

Now it is retrieved from the metadata file.

* Step name is not a required parameter anymore

Since the step name is derived from the config file

* Adjust method signature in test
This commit is contained in:
Marcus Holl 2019-11-22 10:14:21 +01:00 committed by GitHub
parent 7648530b25
commit 0abda0c67b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -62,7 +62,7 @@ func generateConfig() error {
}
}
defaultConfig, paramFilter, err := defaultsAndFilters(&metadata)
defaultConfig, paramFilter, err := defaultsAndFilters(&metadata, metadata.Metadata.Name)
if err != nil {
return errors.Wrap(err, "defaults: retrieving step defaults failed")
}
@ -83,7 +83,7 @@ func generateConfig() error {
params = metadata.Spec.Inputs.Parameters
}
stepConfig, err = myConfig.GetStepConfig(flags, GeneralConfig.ParametersJSON, customConfig, defaultConfig, paramFilter, params, GeneralConfig.StageName, configOptions.stepName)
stepConfig, err = myConfig.GetStepConfig(flags, GeneralConfig.ParametersJSON, customConfig, defaultConfig, paramFilter, params, GeneralConfig.StageName, metadata.Metadata.Name)
if err != nil {
return errors.Wrap(err, "getting step config failed")
}
@ -102,17 +102,15 @@ func addConfigFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&configOptions.parametersJSON, "parametersJSON", os.Getenv("PIPER_parametersJSON"), "Parameters to be considered in JSON format")
cmd.Flags().StringVar(&configOptions.stepMetadata, "stepMetadata", "", "Step metadata, passed as path to yaml")
cmd.Flags().StringVar(&configOptions.stepName, "stepName", "", "Name of the step for which configuration should be included")
cmd.Flags().BoolVar(&configOptions.contextConfig, "contextConfig", false, "Defines if step context configuration should be loaded instead of step config")
cmd.MarkFlagRequired("stepMetadata")
cmd.MarkFlagRequired("stepName")
}
func defaultsAndFilters(metadata *config.StepData) ([]io.ReadCloser, config.StepFilters, error) {
func defaultsAndFilters(metadata *config.StepData, stepName string) ([]io.ReadCloser, config.StepFilters, error) {
if configOptions.contextConfig {
defaults, err := metadata.GetContextDefaults(configOptions.stepName)
defaults, err := metadata.GetContextDefaults(stepName)
if err != nil {
return nil, config.StepFilters{}, errors.Wrap(err, "metadata: getting context defaults failed")
}

View File

@ -41,7 +41,7 @@ func TestConfigCommand(t *testing.T) {
})
t.Run("Required flags", func(t *testing.T) {
exp := []string{"stepMetadata", "stepName"}
exp := []string{"stepMetadata"}
assert.Equal(t, exp, gotReq, "required flags incorrect")
})
@ -73,7 +73,7 @@ func TestDefaultsAndFilters(t *testing.T) {
t.Run("Context config", func(t *testing.T) {
configOptions.contextConfig = true
defer func() { configOptions.contextConfig = false }()
defaults, filters, err := defaultsAndFilters(&metadata)
defaults, filters, err := defaultsAndFilters(&metadata, "stepName")
assert.Equal(t, 1, len(defaults), "getting defaults failed")
assert.Equal(t, 0, len(filters.All), "wrong number of filter values")
@ -81,7 +81,7 @@ func TestDefaultsAndFilters(t *testing.T) {
})
t.Run("Step config", func(t *testing.T) {
defaults, filters, err := defaultsAndFilters(&metadata)
defaults, filters, err := defaultsAndFilters(&metadata, "stepName")
assert.Equal(t, 0, len(defaults), "getting defaults failed")
assert.Equal(t, 1, len(filters.All), "wrong number of filter values")
assert.NoError(t, err, "error occured but none expected")