2019-10-25 14:58:59 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-11-04 17:07:30 +02:00
|
|
|
"os"
|
2019-10-25 14:58:59 +02:00
|
|
|
|
2019-11-07 16:42:22 +02:00
|
|
|
|
2019-10-25 14:58:59 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/config"
|
2019-11-04 15:43:33 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
2019-10-25 14:58:59 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testStepOptions struct {
|
|
|
|
Param0 string `json:"param0,omitempty"`
|
|
|
|
Param1 string `json:"param1,omitempty"`
|
|
|
|
Param2 string `json:"param2,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var myTestStepOptions testStepOptions
|
|
|
|
var testStepStepConfigJSON string
|
|
|
|
|
|
|
|
// TestStepCommand Test description
|
|
|
|
func TestStepCommand() *cobra.Command {
|
|
|
|
metadata := testStepMetadata()
|
|
|
|
var createTestStepCmd = &cobra.Command{
|
|
|
|
Use: "testStep",
|
|
|
|
Short: "Test description",
|
|
|
|
Long: `Long Test description`,
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2019-11-04 15:43:33 +02:00
|
|
|
log.SetStepName("testStep")
|
2019-11-06 17:22:50 +02:00
|
|
|
log.SetVerbose(GeneralConfig.Verbose)
|
|
|
|
return PrepareConfig(cmd, &metadata, "testStep", &myTestStepOptions, OpenPiperFile)
|
2019-10-25 14:58:59 +02:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return testStep(myTestStepOptions)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
addTestStepFlags(createTestStepCmd)
|
|
|
|
return createTestStepCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func addTestStepFlags(cmd *cobra.Command) {
|
|
|
|
cmd.Flags().StringVar(&myTestStepOptions.Param0, "param0", "val0", "param0 description")
|
|
|
|
cmd.Flags().StringVar(&myTestStepOptions.Param1, "param1", os.Getenv("PIPER_param1"), "param1 description")
|
|
|
|
cmd.Flags().StringVar(&myTestStepOptions.Param2, "param2", os.Getenv("PIPER_param2"), "param1 description")
|
|
|
|
|
|
|
|
cmd.MarkFlagRequired("param0")
|
|
|
|
cmd.MarkFlagRequired("param2")
|
|
|
|
}
|
|
|
|
|
|
|
|
// retrieve step metadata
|
|
|
|
func testStepMetadata() config.StepData {
|
|
|
|
var theMetaData = config.StepData{
|
|
|
|
Spec: config.StepSpec{
|
|
|
|
Inputs: config.StepInputs{
|
|
|
|
Parameters: []config.StepParameters{
|
|
|
|
{
|
|
|
|
Name: "param0",
|
|
|
|
Scope: []string{"GENERAL","PARAMETERS",},
|
|
|
|
Type: "string",
|
|
|
|
Mandatory: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "param1",
|
|
|
|
Scope: []string{"PARAMETERS",},
|
|
|
|
Type: "string",
|
|
|
|
Mandatory: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "param2",
|
|
|
|
Scope: []string{"PARAMETERS",},
|
|
|
|
Type: "string",
|
|
|
|
Mandatory: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return theMetaData
|
|
|
|
}
|