You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	Adding new step for abap Enviroment Assembly Confirm (#2586)
* Adding new abap Assembly Confirm * Update abapEnvironmentAssembleConfirm.go * Add generated objects Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							8c030784e1
						
					
				
				
					commit
					e9a93ed384
				
			
							
								
								
									
										122
									
								
								cmd/abapEnvironmentAssembleConfirm.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								cmd/abapEnvironmentAssembleConfirm.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,122 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"time" | ||||
|  | ||||
| 	abapbuild "github.com/SAP/jenkins-library/pkg/abap/build" | ||||
| 	"github.com/SAP/jenkins-library/pkg/abaputils" | ||||
| 	"github.com/SAP/jenkins-library/pkg/command" | ||||
| 	piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||
| 	"github.com/SAP/jenkins-library/pkg/log" | ||||
| 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||
| 	"github.com/pkg/errors" | ||||
| ) | ||||
|  | ||||
| func abapEnvironmentAssembleConfirm(config abapEnvironmentAssembleConfirmOptions, telemetryData *telemetry.CustomData, cpe *abapEnvironmentAssembleConfirmCommonPipelineEnvironment) { | ||||
| 	// for command execution use Command | ||||
| 	c := command.Command{} | ||||
| 	// reroute command output to logging framework | ||||
| 	c.Stdout(log.Writer()) | ||||
| 	c.Stderr(log.Writer()) | ||||
|  | ||||
| 	var autils = abaputils.AbapUtils{ | ||||
| 		Exec: &c, | ||||
| 	} | ||||
|  | ||||
| 	client := piperhttp.Client{} | ||||
| 	err := runAbapEnvironmentAssembleConfirm(&config, telemetryData, &autils, &client, cpe) | ||||
| 	if err != nil { | ||||
| 		log.Entry().WithError(err).Fatal("step execution failed") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func runAbapEnvironmentAssembleConfirm(config *abapEnvironmentAssembleConfirmOptions, telemetryData *telemetry.CustomData, com abaputils.Communication, client piperhttp.Sender, cpe *abapEnvironmentAssembleConfirmCommonPipelineEnvironment) error { | ||||
| 	conn := new(abapbuild.Connector) | ||||
| 	var connConfig abapbuild.ConnectorConfiguration | ||||
| 	connConfig.CfAPIEndpoint = config.CfAPIEndpoint | ||||
| 	connConfig.CfOrg = config.CfOrg | ||||
| 	connConfig.CfSpace = config.CfSpace | ||||
| 	connConfig.CfServiceInstance = config.CfServiceInstance | ||||
| 	connConfig.CfServiceKeyName = config.CfServiceKeyName | ||||
| 	connConfig.Host = config.Host | ||||
| 	connConfig.Username = config.Username | ||||
| 	connConfig.Password = config.Password | ||||
| 	connConfig.AddonDescriptor = config.AddonDescriptor | ||||
| 	connConfig.MaxRuntimeInMinutes = config.MaxRuntimeInMinutes | ||||
|  | ||||
| 	err := conn.InitBuildFramework(connConfig, com, client) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var addonDescriptor abaputils.AddonDescriptor | ||||
| 	err = json.Unmarshal([]byte(config.AddonDescriptor), &addonDescriptor) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	delayBetweenPostsInSeconds := time.Duration(3 * time.Second) | ||||
| 	builds, err := startingConfirm(addonDescriptor.Repositories, *conn, delayBetweenPostsInSeconds) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	maxRuntimeInMinutes := time.Duration(config.MaxRuntimeInMinutes) * time.Minute | ||||
| 	pollIntervalsInSeconds := time.Duration(60 * time.Second) | ||||
| 	err = polling(builds, maxRuntimeInMinutes, pollIntervalsInSeconds) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	err = checkIfFailedAndPrintLogs(builds) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func startingConfirm(repos []abaputils.Repository, conn abapbuild.Connector, delayBetweenPostsInSeconds time.Duration) ([]buildWithRepository, error) { | ||||
| 	var builds []buildWithRepository | ||||
| 	var buildsAlreadyReleased []buildWithRepository | ||||
| 	for _, repo := range repos { | ||||
| 		assemblyBuild := abapbuild.Build{ | ||||
| 			Connector: conn, | ||||
| 		} | ||||
| 		buildRepo := buildWithRepository{ | ||||
| 			build: assemblyBuild, | ||||
| 			repo:  repo, | ||||
| 		} | ||||
| 		if repo.Status == "P" { | ||||
| 			err := buildRepo.startConfirm() | ||||
| 			if err != nil { | ||||
| 				return builds, err | ||||
| 			} | ||||
| 			builds = append(builds, buildRepo) | ||||
| 		} else { | ||||
| 			log.Entry().Infof("Packages %s is in status '%s'. No need assembly done, no need to confirm", repo.PackageName, repo.Status) | ||||
| 			buildsAlreadyReleased = append(buildsAlreadyReleased, buildRepo) | ||||
| 		} | ||||
|  | ||||
| 		//as batch events in the ABAP Backend need a little time | ||||
| 		time.Sleep(delayBetweenPostsInSeconds) | ||||
| 	} | ||||
| 	return builds, nil | ||||
| } | ||||
|  | ||||
| func (b *buildWithRepository) startConfirm() error { | ||||
| 	if b.repo.Name == "" || b.repo.Namespace == "" || b.repo.PackageName == "" { | ||||
| 		return errors.New("Parameters missing. Please provide software component name, namespace and packagename") | ||||
| 	} | ||||
| 	valuesInput := abapbuild.Values{ | ||||
| 		Values: []abapbuild.Value{ | ||||
| 			{ | ||||
| 				ValueID: "SWC", | ||||
| 				Value:   b.repo.Name, | ||||
| 			}, | ||||
| 			{ | ||||
| 				ValueID: "SSDC-delta", | ||||
| 				Value:   b.repo.Namespace + b.repo.PackageName, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	phase := "BUILD_CONFIRM" | ||||
| 	log.Entry().Infof("Starting confirmation of package %s", b.repo.PackageName) | ||||
| 	return b.build.Start(phase, valuesInput) | ||||
| } | ||||
							
								
								
									
										252
									
								
								cmd/abapEnvironmentAssembleConfirm_generated.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										252
									
								
								cmd/abapEnvironmentAssembleConfirm_generated.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,252 @@ | ||||
| // Code generated by piper's step-generator. DO NOT EDIT. | ||||
|  | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/SAP/jenkins-library/pkg/config" | ||||
| 	"github.com/SAP/jenkins-library/pkg/log" | ||||
| 	"github.com/SAP/jenkins-library/pkg/piperenv" | ||||
| 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||
| 	"github.com/spf13/cobra" | ||||
| ) | ||||
|  | ||||
| type abapEnvironmentAssembleConfirmOptions struct { | ||||
| 	CfAPIEndpoint       string `json:"cfApiEndpoint,omitempty"` | ||||
| 	CfOrg               string `json:"cfOrg,omitempty"` | ||||
| 	CfSpace             string `json:"cfSpace,omitempty"` | ||||
| 	CfServiceInstance   string `json:"cfServiceInstance,omitempty"` | ||||
| 	CfServiceKeyName    string `json:"cfServiceKeyName,omitempty"` | ||||
| 	Host                string `json:"host,omitempty"` | ||||
| 	Username            string `json:"username,omitempty"` | ||||
| 	Password            string `json:"password,omitempty"` | ||||
| 	AddonDescriptor     string `json:"addonDescriptor,omitempty"` | ||||
| 	MaxRuntimeInMinutes int    `json:"maxRuntimeInMinutes,omitempty"` | ||||
| } | ||||
|  | ||||
| type abapEnvironmentAssembleConfirmCommonPipelineEnvironment struct { | ||||
| 	abap struct { | ||||
| 		addonDescriptor string | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p *abapEnvironmentAssembleConfirmCommonPipelineEnvironment) persist(path, resourceName string) { | ||||
| 	content := []struct { | ||||
| 		category string | ||||
| 		name     string | ||||
| 		value    interface{} | ||||
| 	}{ | ||||
| 		{category: "abap", name: "addonDescriptor", value: p.abap.addonDescriptor}, | ||||
| 	} | ||||
|  | ||||
| 	errCount := 0 | ||||
| 	for _, param := range content { | ||||
| 		err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) | ||||
| 		if err != nil { | ||||
| 			log.Entry().WithError(err).Error("Error persisting piper environment.") | ||||
| 			errCount++ | ||||
| 		} | ||||
| 	} | ||||
| 	if errCount > 0 { | ||||
| 		log.Entry().Fatal("failed to persist Piper environment") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // AbapEnvironmentAssembleConfirmCommand Confirm the Delivery of Assembly for installation, support package or patch in SAP Cloud Platform ABAP Environment system | ||||
| func AbapEnvironmentAssembleConfirmCommand() *cobra.Command { | ||||
| 	const STEP_NAME = "abapEnvironmentAssembleConfirm" | ||||
|  | ||||
| 	metadata := abapEnvironmentAssembleConfirmMetadata() | ||||
| 	var stepConfig abapEnvironmentAssembleConfirmOptions | ||||
| 	var startTime time.Time | ||||
| 	var commonPipelineEnvironment abapEnvironmentAssembleConfirmCommonPipelineEnvironment | ||||
|  | ||||
| 	var createAbapEnvironmentAssembleConfirmCmd = &cobra.Command{ | ||||
| 		Use:   STEP_NAME, | ||||
| 		Short: "Confirm the Delivery of Assembly for installation, support package or patch in SAP Cloud Platform ABAP Environment system", | ||||
| 		Long:  `This step confirms the assemblies of provided [installations, support packages or patches] in SAP Cloud Platform ABAP Environment system`, | ||||
| 		PreRunE: func(cmd *cobra.Command, _ []string) error { | ||||
| 			startTime = time.Now() | ||||
| 			log.SetStepName(STEP_NAME) | ||||
| 			log.SetVerbose(GeneralConfig.Verbose) | ||||
|  | ||||
| 			path, _ := os.Getwd() | ||||
| 			fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} | ||||
| 			log.RegisterHook(fatalHook) | ||||
|  | ||||
| 			err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) | ||||
| 			if err != nil { | ||||
| 				log.SetErrorCategory(log.ErrorConfiguration) | ||||
| 				return err | ||||
| 			} | ||||
| 			log.RegisterSecret(stepConfig.Username) | ||||
| 			log.RegisterSecret(stepConfig.Password) | ||||
|  | ||||
| 			if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { | ||||
| 				sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) | ||||
| 				log.RegisterHook(&sentryHook) | ||||
| 			} | ||||
|  | ||||
| 			return nil | ||||
| 		}, | ||||
| 		Run: func(_ *cobra.Command, _ []string) { | ||||
| 			telemetryData := telemetry.CustomData{} | ||||
| 			telemetryData.ErrorCode = "1" | ||||
| 			handler := func() { | ||||
| 				config.RemoveVaultSecretFiles() | ||||
| 				commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") | ||||
| 				telemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) | ||||
| 				telemetryData.ErrorCategory = log.GetErrorCategory().String() | ||||
| 				telemetry.Send(&telemetryData) | ||||
| 			} | ||||
| 			log.DeferExitHandler(handler) | ||||
| 			defer handler() | ||||
| 			telemetry.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) | ||||
| 			abapEnvironmentAssembleConfirm(stepConfig, &telemetryData, &commonPipelineEnvironment) | ||||
| 			telemetryData.ErrorCode = "0" | ||||
| 			log.Entry().Info("SUCCESS") | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	addAbapEnvironmentAssembleConfirmFlags(createAbapEnvironmentAssembleConfirmCmd, &stepConfig) | ||||
| 	return createAbapEnvironmentAssembleConfirmCmd | ||||
| } | ||||
|  | ||||
| func addAbapEnvironmentAssembleConfirmFlags(cmd *cobra.Command, stepConfig *abapEnvironmentAssembleConfirmOptions) { | ||||
| 	cmd.Flags().StringVar(&stepConfig.CfAPIEndpoint, "cfApiEndpoint", os.Getenv("PIPER_cfApiEndpoint"), "Cloud Foundry API endpoint") | ||||
| 	cmd.Flags().StringVar(&stepConfig.CfOrg, "cfOrg", os.Getenv("PIPER_cfOrg"), "Cloud Foundry target organization") | ||||
| 	cmd.Flags().StringVar(&stepConfig.CfSpace, "cfSpace", os.Getenv("PIPER_cfSpace"), "Cloud Foundry target space") | ||||
| 	cmd.Flags().StringVar(&stepConfig.CfServiceInstance, "cfServiceInstance", os.Getenv("PIPER_cfServiceInstance"), "Cloud Foundry Service Instance") | ||||
| 	cmd.Flags().StringVar(&stepConfig.CfServiceKeyName, "cfServiceKeyName", os.Getenv("PIPER_cfServiceKeyName"), "Cloud Foundry Service Key") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the host address of the SAP Cloud Platform ABAP Environment system") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0582") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0582") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions") | ||||
| 	cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 360, "maximal runtime of the step") | ||||
|  | ||||
| 	cmd.MarkFlagRequired("username") | ||||
| 	cmd.MarkFlagRequired("password") | ||||
| 	cmd.MarkFlagRequired("addonDescriptor") | ||||
| 	cmd.MarkFlagRequired("maxRuntimeInMinutes") | ||||
| } | ||||
|  | ||||
| // retrieve step metadata | ||||
| func abapEnvironmentAssembleConfirmMetadata() config.StepData { | ||||
| 	var theMetaData = config.StepData{ | ||||
| 		Metadata: config.StepMetadata{ | ||||
| 			Name:        "abapEnvironmentAssembleConfirm", | ||||
| 			Aliases:     []config.Alias{}, | ||||
| 			Description: "Confirm the Delivery of Assembly for installation, support package or patch in SAP Cloud Platform ABAP Environment system", | ||||
| 		}, | ||||
| 		Spec: config.StepSpec{ | ||||
| 			Inputs: config.StepInputs{ | ||||
| 				Parameters: []config.StepParameters{ | ||||
| 					{ | ||||
| 						Name:        "cfApiEndpoint", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{{Name: "cloudFoundry/apiEndpoint"}}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "cfOrg", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{{Name: "cloudFoundry/org"}}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "cfSpace", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{{Name: "cloudFoundry/space"}}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "cfServiceInstance", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{{Name: "cloudFoundry/serviceInstance"}}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "cfServiceKeyName", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{{Name: "cloudFoundry/serviceKey"}, {Name: "cloudFoundry/serviceKeyName"}, {Name: "cfServiceKey"}}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "host", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "username", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "password", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name: "addonDescriptor", | ||||
| 						ResourceRef: []config.ResourceReference{ | ||||
| 							{ | ||||
| 								Name:  "commonPipelineEnvironment", | ||||
| 								Param: "abap/addonDescriptor", | ||||
| 							}, | ||||
| 						}, | ||||
| 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:      "string", | ||||
| 						Mandatory: true, | ||||
| 						Aliases:   []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "maxRuntimeInMinutes", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "int", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			Containers: []config.Container{ | ||||
| 				{Name: "cf", Image: "ppiper/cf-cli"}, | ||||
| 			}, | ||||
| 			Outputs: config.StepOutputs{ | ||||
| 				Resources: []config.StepResources{ | ||||
| 					{ | ||||
| 						Name: "commonPipelineEnvironment", | ||||
| 						Type: "piperEnvironment", | ||||
| 						Parameters: []map[string]interface{}{ | ||||
| 							{"Name": "abap/addonDescriptor"}, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	return theMetaData | ||||
| } | ||||
							
								
								
									
										17
									
								
								cmd/abapEnvironmentAssembleConfirm_generated_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								cmd/abapEnvironmentAssembleConfirm_generated_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestAbapEnvironmentAssembleConfirmCommand(t *testing.T) { | ||||
| 	t.Parallel() | ||||
|  | ||||
| 	testCmd := AbapEnvironmentAssembleConfirmCommand() | ||||
|  | ||||
| 	// only high level testing performed - details are tested in step generation procedure | ||||
| 	assert.Equal(t, "abapEnvironmentAssembleConfirm", testCmd.Use, "command name incorrect") | ||||
|  | ||||
| } | ||||
							
								
								
									
										72
									
								
								cmd/abapEnvironmentAssembleConfirm_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								cmd/abapEnvironmentAssembleConfirm_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
| 	"time" | ||||
|  | ||||
| 	abapbuild "github.com/SAP/jenkins-library/pkg/abap/build" | ||||
| 	"github.com/SAP/jenkins-library/pkg/abaputils" | ||||
| 	piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func testSetupConfirm(client piperhttp.Sender, buildID string) abapbuild.Build { | ||||
| 	conn := new(abapbuild.Connector) | ||||
| 	conn.Client = client | ||||
| 	conn.DownloadClient = &abapbuild.DownloadClientMock{} | ||||
| 	conn.Header = make(map[string][]string) | ||||
| 	b := abapbuild.Build{ | ||||
| 		Connector: *conn, | ||||
| 		BuildID:   buildID, | ||||
| 	} | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func TestStartingConfirm(t *testing.T) { | ||||
| 	t.Run("Run starting", func(t *testing.T) { | ||||
| 		client := &abapbuild.ClMock{ | ||||
| 			Token: "MyToken", | ||||
| 		} | ||||
| 		conn := new(abapbuild.Connector) | ||||
| 		conn.Client = client | ||||
| 		conn.Header = make(map[string][]string) | ||||
| 		var repos []abaputils.Repository | ||||
| 		repo := abaputils.Repository{ | ||||
| 			Name:        "RepoA", | ||||
| 			Version:     "0001", | ||||
| 			PackageName: "Package", | ||||
| 			PackageType: "AOI", | ||||
| 			SpLevel:     "0000", | ||||
| 			PatchLevel:  "0000", | ||||
| 			Status:      "P", | ||||
| 			Namespace:   "/DEMO/", | ||||
| 		} | ||||
| 		repos = append(repos, repo) | ||||
| 		repo.Status = "R" | ||||
| 		repos = append(repos, repo) | ||||
|  | ||||
| 		builds, err := startingConfirm(repos, *conn, time.Duration(0*time.Second)) | ||||
| 		assert.NoError(t, err) | ||||
| 		assert.Equal(t, 1, len(builds)) | ||||
| 		assert.Equal(t, abapbuild.Accepted, builds[0].build.RunState) | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func TestStartingConfirmInvalidInput(t *testing.T) { | ||||
| 	t.Run("Run starting", func(t *testing.T) { | ||||
| 		client := &abapbuild.ClMock{ | ||||
| 			Token: "MyToken", | ||||
| 		} | ||||
| 		conn := new(abapbuild.Connector) | ||||
| 		conn.Client = client | ||||
| 		conn.Header = make(map[string][]string) | ||||
| 		var repos []abaputils.Repository | ||||
| 		repo := abaputils.Repository{ | ||||
| 			Name:   "RepoA", | ||||
| 			Status: "P", | ||||
| 		} | ||||
| 		repos = append(repos, repo) | ||||
| 		_, err := startingConfirm(repos, *conn, time.Duration(0*time.Second)) | ||||
| 		assert.Error(t, err) | ||||
| 	}) | ||||
| } | ||||
| @@ -14,6 +14,7 @@ func GetAllStepMetadata() map[string]config.StepData { | ||||
| 		"abapAddonAssemblyKitRegisterPackages":    abapAddonAssemblyKitRegisterPackagesMetadata(), | ||||
| 		"abapAddonAssemblyKitReleasePackages":     abapAddonAssemblyKitReleasePackagesMetadata(), | ||||
| 		"abapAddonAssemblyKitReserveNextPackages": abapAddonAssemblyKitReserveNextPackagesMetadata(), | ||||
| 		"abapEnvironmentAssembleConfirm":          abapEnvironmentAssembleConfirmMetadata(), | ||||
| 		"abapEnvironmentAssemblePackages":         abapEnvironmentAssemblePackagesMetadata(), | ||||
| 		"abapEnvironmentCheckoutBranch":           abapEnvironmentCheckoutBranchMetadata(), | ||||
| 		"abapEnvironmentCloneGitRepo":             abapEnvironmentCloneGitRepoMetadata(), | ||||
|   | ||||
| @@ -125,6 +125,7 @@ func Execute() { | ||||
| 	rootCmd.AddCommand(IntegrationArtifactDeployCommand()) | ||||
| 	rootCmd.AddCommand(IntegrationArtifactUpdateConfigurationCommand()) | ||||
| 	rootCmd.AddCommand(IntegrationArtifactGetMplStatusCommand()) | ||||
| 	rootCmd.AddCommand(AbapEnvironmentAssembleConfirmCommand()) | ||||
|  | ||||
| 	addRootFlags(rootCmd) | ||||
| 	if err := rootCmd.Execute(); err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user