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 
			
		
		
		
	[refactoring] Make room for other upload action: move package (#2518)
* [refactoring] Make room for other upload action: move package In the near future we will have more upload actions, like SOLMAN, RFC. Here we prepare the package structure for that. * don't use aliasing * rename entities (no leading CTS)
This commit is contained in:
		| @@ -4,7 +4,7 @@ import ( | ||||
| 	"github.com/SAP/jenkins-library/pkg/command" | ||||
| 	"github.com/SAP/jenkins-library/pkg/log" | ||||
| 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||
| 	"github.com/SAP/jenkins-library/pkg/transportrequest" | ||||
| 	"github.com/SAP/jenkins-library/pkg/transportrequest/cts" | ||||
| ) | ||||
|  | ||||
| type transportRequestUploadUtils interface { | ||||
| @@ -16,12 +16,12 @@ type transportRequestUploadUtils interface { | ||||
| 	// Unit tests shall be executable in parallel (not depend on global state), and don't (re-)test dependencies. | ||||
| } | ||||
|  | ||||
| // CTSUploadAction ... | ||||
| type CTSUploadAction interface { | ||||
| // UploadAction ... | ||||
| type UploadAction interface { | ||||
| 	Perform(command.ShellRunner) error | ||||
| 	WithConnection(transportrequest.CTSConnection) | ||||
| 	WithApplication(transportrequest.CTSApplication) | ||||
| 	WithNodeProperties(transportrequest.CTSNode) | ||||
| 	WithConnection(cts.Connection) | ||||
| 	WithApplication(cts.Application) | ||||
| 	WithNodeProperties(cts.Node) | ||||
| 	WithTransportRequestID(string) | ||||
| 	WithConfigFile(string) | ||||
| 	WithDeployUser(string) | ||||
| @@ -57,7 +57,7 @@ func transportRequestUploadCTS(config transportRequestUploadCTSOptions, telemetr | ||||
|  | ||||
| 	// Error situations should be bubbled up until they reach the line below which will then stop execution | ||||
| 	// through the log.Entry().Fatal() call leading to an os.Exit(1) in the end. | ||||
| 	err := runTransportRequestUploadCTS(&config, &transportrequest.CTSUploadAction{}, telemetryData, utils) | ||||
| 	err := runTransportRequestUploadCTS(&config, &cts.UploadAction{}, telemetryData, utils) | ||||
| 	if err != nil { | ||||
| 		log.Entry().WithError(err).Fatal("step execution failed") | ||||
| 	} | ||||
| @@ -65,24 +65,24 @@ func transportRequestUploadCTS(config transportRequestUploadCTSOptions, telemetr | ||||
|  | ||||
| func runTransportRequestUploadCTS( | ||||
| 	config *transportRequestUploadCTSOptions, | ||||
| 	action CTSUploadAction, | ||||
| 	action UploadAction, | ||||
| 	telemetryData *telemetry.CustomData, | ||||
| 	cmd command.ShellRunner) error { | ||||
|  | ||||
| 	log.Entry().Debugf("Entering 'runTransportRequestUpload' with config: %v", config) | ||||
|  | ||||
| 	action.WithConnection(transportrequest.CTSConnection{ | ||||
| 	action.WithConnection(cts.Connection{ | ||||
| 		Endpoint: config.Endpoint, | ||||
| 		Client:   config.Client, | ||||
| 		User:     config.Username, | ||||
| 		Password: config.Password, | ||||
| 	}) | ||||
| 	action.WithApplication(transportrequest.CTSApplication{ | ||||
| 	action.WithApplication(cts.Application{ | ||||
| 		Name: config.ApplicationName, | ||||
| 		Pack: config.AbapPackage, | ||||
| 		Desc: config.Description, | ||||
| 	}) | ||||
| 	action.WithNodeProperties(transportrequest.CTSNode{ | ||||
| 	action.WithNodeProperties(cts.Node{ | ||||
| 		DeployDependencies: config.DeployToolDependencies, | ||||
| 		InstallOpts:        config.NpmInstallOpts, | ||||
| 	}) | ||||
|   | ||||
| @@ -4,15 +4,15 @@ import ( | ||||
| 	"fmt" | ||||
| 	"github.com/SAP/jenkins-library/pkg/command" | ||||
| 	"github.com/SAP/jenkins-library/pkg/mock" | ||||
| 	"github.com/SAP/jenkins-library/pkg/transportrequest" | ||||
| 	transportrequest "github.com/SAP/jenkins-library/pkg/transportrequest/cts" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| 	"testing" | ||||
| ) | ||||
|  | ||||
| type CTSUploadActionMock struct { | ||||
| 	Connection         transportrequest.CTSConnection | ||||
| 	Application        transportrequest.CTSApplication | ||||
| 	Node               transportrequest.CTSNode | ||||
| type UploadActionMock struct { | ||||
| 	Connection         transportrequest.Connection | ||||
| 	Application        transportrequest.Application | ||||
| 	Node               transportrequest.Node | ||||
| 	TransportRequestID string | ||||
| 	ConfigFile         string | ||||
| 	DeployUser         string | ||||
| @@ -20,36 +20,36 @@ type CTSUploadActionMock struct { | ||||
| } | ||||
|  | ||||
| // WithConnection ... | ||||
| func (action *CTSUploadActionMock) WithConnection(connection transportrequest.CTSConnection) { | ||||
| func (action *UploadActionMock) WithConnection(connection transportrequest.Connection) { | ||||
| 	action.Connection = connection | ||||
| } | ||||
|  | ||||
| // WithApplication ... | ||||
| func (action *CTSUploadActionMock) WithApplication(app transportrequest.CTSApplication) { | ||||
| func (action *UploadActionMock) WithApplication(app transportrequest.Application) { | ||||
| 	action.Application = app | ||||
| } | ||||
|  | ||||
| // WithNodeProperties ... | ||||
| func (action *CTSUploadActionMock) WithNodeProperties(node transportrequest.CTSNode) { | ||||
| func (action *UploadActionMock) WithNodeProperties(node transportrequest.Node) { | ||||
| 	action.Node = node | ||||
| } | ||||
|  | ||||
| // WithTransportRequestID ... | ||||
| func (action *CTSUploadActionMock) WithTransportRequestID(id string) { | ||||
| func (action *UploadActionMock) WithTransportRequestID(id string) { | ||||
| 	action.TransportRequestID = id | ||||
| } | ||||
|  | ||||
| // WithConfigFile ... | ||||
| func (action *CTSUploadActionMock) WithConfigFile(configFile string) { | ||||
| func (action *UploadActionMock) WithConfigFile(configFile string) { | ||||
| 	action.ConfigFile = configFile | ||||
| } | ||||
|  | ||||
| // WithDeployUser ... | ||||
| func (action *CTSUploadActionMock) WithDeployUser(deployUser string) { | ||||
| func (action *UploadActionMock) WithDeployUser(deployUser string) { | ||||
| 	action.DeployUser = deployUser | ||||
| } | ||||
|  | ||||
| func (action *CTSUploadActionMock) Perform(cmd command.ShellRunner) error { | ||||
| func (action *UploadActionMock) Perform(cmd command.ShellRunner) error { | ||||
| 	return action.thrown | ||||
| } | ||||
|  | ||||
| @@ -84,25 +84,25 @@ func TestRunTransportRequestUploadCTS(t *testing.T) { | ||||
| 			NpmInstallOpts:         []string{"--verbose", "--registry", "https://registry.example.org/"}, | ||||
| 		} | ||||
|  | ||||
| 		actionMock := &CTSUploadActionMock{thrown: nil} | ||||
| 		actionMock := &UploadActionMock{thrown: nil} | ||||
| 		// test | ||||
| 		err := runTransportRequestUploadCTS(&config, actionMock, nil, newTransportRequestUploadCTSTestsUtils()) | ||||
|  | ||||
| 		// assert | ||||
| 		if assert.NoError(t, err) { | ||||
| 			assert.Equal(t, &CTSUploadActionMock{ | ||||
| 				Connection: transportrequest.CTSConnection{ | ||||
| 			assert.Equal(t, &UploadActionMock{ | ||||
| 				Connection: transportrequest.Connection{ | ||||
| 					Endpoint: "https://example.org:8000", | ||||
| 					Client:   "001", | ||||
| 					User:     "me", | ||||
| 					Password: "********", | ||||
| 				}, | ||||
| 				Application: transportrequest.CTSApplication{ | ||||
| 				Application: transportrequest.Application{ | ||||
| 					Name: "myApp", | ||||
| 					Pack: "myPackage", | ||||
| 					Desc: "lorem ipsum", | ||||
| 				}, | ||||
| 				Node: transportrequest.CTSNode{ | ||||
| 				Node: transportrequest.Node{ | ||||
| 					DeployDependencies: []string{ | ||||
| 						"@ui5/cli", | ||||
| 						"@sap/ux-ui5-tooling", | ||||
| @@ -139,7 +139,7 @@ func TestRunTransportRequestUploadCTS(t *testing.T) { | ||||
|  | ||||
| 		err := runTransportRequestUploadCTS( | ||||
| 			&config, | ||||
| 			&CTSUploadActionMock{thrown: fmt.Errorf("something went wrong")}, | ||||
| 			&UploadActionMock{thrown: fmt.Errorf("something went wrong")}, | ||||
| 			nil, | ||||
| 			newTransportRequestUploadCTSTestsUtils()) | ||||
| 		assert.EqualError(t, err, "something went wrong") | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| package transportrequest | ||||
| package cts | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| @@ -14,8 +14,8 @@ type fileUtils interface { | ||||
| 
 | ||||
| var files fileUtils = piperutils.Files{} | ||||
| 
 | ||||
| // CTSConnection Everything wee need for connecting to CTS | ||||
| type CTSConnection struct { | ||||
| // Connection Everything wee need for connecting to CTS | ||||
| type Connection struct { | ||||
| 	// The endpoint in for form <protocol>://<host>:<port>, no path | ||||
| 	Endpoint string | ||||
| 	// The ABAP client, like e.g. "001" | ||||
| @@ -24,8 +24,8 @@ type CTSConnection struct { | ||||
| 	Password string | ||||
| } | ||||
| 
 | ||||
| // CTSApplication The details of the application | ||||
| type CTSApplication struct { | ||||
| // Application The details of the application | ||||
| type Application struct { | ||||
| 	// Name of the application | ||||
| 	Name string | ||||
| 	// The ABAP package | ||||
| @@ -35,8 +35,8 @@ type CTSApplication struct { | ||||
| 	Desc string | ||||
| } | ||||
| 
 | ||||
| // CTSNode The details for configuring the node image | ||||
| type CTSNode struct { | ||||
| // Node The details for configuring the node image | ||||
| type Node struct { | ||||
| 	// The dependencies which are installed on a basic node image in order | ||||
| 	// to enable it for fiori deployment. If left empty we assume the | ||||
| 	// provided base image has already everything installed. | ||||
| @@ -46,11 +46,11 @@ type CTSNode struct { | ||||
| 	InstallOpts []string | ||||
| } | ||||
| 
 | ||||
| // CTSUploadAction Collects all the properties we need for the deployment | ||||
| type CTSUploadAction struct { | ||||
| 	Connection         CTSConnection | ||||
| 	Application        CTSApplication | ||||
| 	Node               CTSNode | ||||
| // UploadAction Collects all the properties we need for the deployment | ||||
| type UploadAction struct { | ||||
| 	Connection         Connection | ||||
| 	Application        Application | ||||
| 	Node               Node | ||||
| 	TransportRequestID string | ||||
| 	ConfigFile         string | ||||
| 	DeployUser         string | ||||
| @@ -63,37 +63,37 @@ const ( | ||||
| ) | ||||
| 
 | ||||
| // WithConnection ... | ||||
| func (action *CTSUploadAction) WithConnection(connection CTSConnection) { | ||||
| func (action *UploadAction) WithConnection(connection Connection) { | ||||
| 	action.Connection = connection | ||||
| } | ||||
| 
 | ||||
| // WithApplication ... | ||||
| func (action *CTSUploadAction) WithApplication(app CTSApplication) { | ||||
| func (action *UploadAction) WithApplication(app Application) { | ||||
| 	action.Application = app | ||||
| } | ||||
| 
 | ||||
| // WithNodeProperties ... | ||||
| func (action *CTSUploadAction) WithNodeProperties(node CTSNode) { | ||||
| func (action *UploadAction) WithNodeProperties(node Node) { | ||||
| 	action.Node = node | ||||
| } | ||||
| 
 | ||||
| // WithTransportRequestID ... | ||||
| func (action *CTSUploadAction) WithTransportRequestID(id string) { | ||||
| func (action *UploadAction) WithTransportRequestID(id string) { | ||||
| 	action.TransportRequestID = id | ||||
| } | ||||
| 
 | ||||
| // WithConfigFile ... | ||||
| func (action *CTSUploadAction) WithConfigFile(configFile string) { | ||||
| func (action *UploadAction) WithConfigFile(configFile string) { | ||||
| 	action.ConfigFile = configFile | ||||
| } | ||||
| 
 | ||||
| // WithDeployUser ... | ||||
| func (action *CTSUploadAction) WithDeployUser(deployUser string) { | ||||
| func (action *UploadAction) WithDeployUser(deployUser string) { | ||||
| 	action.DeployUser = deployUser | ||||
| } | ||||
| 
 | ||||
| // Perform Performs the upload | ||||
| func (action *CTSUploadAction) Perform(command command.ShellRunner) error { | ||||
| func (action *UploadAction) Perform(command command.ShellRunner) error { | ||||
| 
 | ||||
| 	command.AppendEnv( | ||||
| 		[]string{ | ||||
| @@ -136,8 +136,8 @@ func getPrepareFioriEnvironmentStatement(deps []string, npmInstallOpts []string) | ||||
| func getFioriDeployStatement( | ||||
| 	transportRequestID string, | ||||
| 	configFile string, | ||||
| 	app CTSApplication, | ||||
| 	cts CTSConnection, | ||||
| 	app Application, | ||||
| 	cts Connection, | ||||
| ) (string, error) { | ||||
| 	desc := app.Desc | ||||
| 	if len(desc) == 0 { | ||||
| @@ -1,4 +1,4 @@ | ||||
| package transportrequest | ||||
| package cts | ||||
| 
 | ||||
| import ( | ||||
| 	"github.com/SAP/jenkins-library/pkg/mock" | ||||
| @@ -15,10 +15,10 @@ func TestUploadCTS(t *testing.T) { | ||||
| 
 | ||||
| 	t.Run("npm install command tests", func(t *testing.T) { | ||||
| 		cmd := mock.ShellMockRunner{} | ||||
| 		action := CTSUploadAction{ | ||||
| 			Connection:  CTSConnection{Endpoint: "", Client: "", User: "me", Password: "******"}, | ||||
| 			Application: CTSApplication{Pack: "", Name: "", Desc: ""}, | ||||
| 			Node: CTSNode{ | ||||
| 		action := UploadAction{ | ||||
| 			Connection:  Connection{Endpoint: "", Client: "", User: "me", Password: "******"}, | ||||
| 			Application: Application{Pack: "", Name: "", Desc: ""}, | ||||
| 			Node: Node{ | ||||
| 				DeployDependencies: []string{"@sap/my-dep"}, | ||||
| 				InstallOpts:        []string{"--verbose", "--registry", "https://registry.example.org"}, | ||||
| 			}, | ||||
| @@ -46,10 +46,10 @@ func TestUploadCTS(t *testing.T) { | ||||
| 	t.Run("deploy command tests", func(t *testing.T) { | ||||
| 		t.Run("all possible values provided", func(t *testing.T) { | ||||
| 			cmd := mock.ShellMockRunner{} | ||||
| 			action := CTSUploadAction{ | ||||
| 				Connection:  CTSConnection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"}, | ||||
| 				Application: CTSApplication{Pack: "abapPackage", Name: "appName", Desc: "the Desc"}, | ||||
| 				Node: CTSNode{ | ||||
| 			action := UploadAction{ | ||||
| 				Connection:  Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"}, | ||||
| 				Application: Application{Pack: "abapPackage", Name: "appName", Desc: "the Desc"}, | ||||
| 				Node: Node{ | ||||
| 					DeployDependencies: []string{}, | ||||
| 					InstallOpts:        []string{}, | ||||
| 				}, | ||||
| @@ -73,10 +73,10 @@ func TestUploadCTS(t *testing.T) { | ||||
| 		t.Run("all possible values omitted", func(t *testing.T) { | ||||
| 			// In this case the values are expected inside the fiori deploy config file | ||||
| 			cmd := mock.ShellMockRunner{} | ||||
| 			action := CTSUploadAction{ | ||||
| 				Connection:  CTSConnection{Endpoint: "", Client: "", User: "me", Password: "******"}, | ||||
| 				Application: CTSApplication{Pack: "", Name: "", Desc: ""}, | ||||
| 				Node: CTSNode{ | ||||
| 			action := UploadAction{ | ||||
| 				Connection:  Connection{Endpoint: "", Client: "", User: "me", Password: "******"}, | ||||
| 				Application: Application{Pack: "", Name: "", Desc: ""}, | ||||
| 				Node: Node{ | ||||
| 					DeployDependencies: []string{}, | ||||
| 					InstallOpts:        []string{}, | ||||
| 				}, | ||||
| @@ -99,9 +99,9 @@ func TestUploadCTS(t *testing.T) { | ||||
| 	}) | ||||
| 
 | ||||
| 	t.Run("config file releated tests", func(t *testing.T) { | ||||
| 		connection := CTSConnection{Endpoint: "", Client: "", User: "me", Password: "******"} | ||||
| 		app := CTSApplication{Pack: "", Name: "", Desc: ""} | ||||
| 		node := CTSNode{ | ||||
| 		connection := Connection{Endpoint: "", Client: "", User: "me", Password: "******"} | ||||
| 		app := Application{Pack: "", Name: "", Desc: ""} | ||||
| 		node := Node{ | ||||
| 			DeployDependencies: []string{}, | ||||
| 			InstallOpts:        []string{}, | ||||
| 		} | ||||
| @@ -111,7 +111,7 @@ func TestUploadCTS(t *testing.T) { | ||||
| 			files = &filesMock | ||||
| 			defer func() { files = fMock }() | ||||
| 			cmd := mock.ShellMockRunner{} | ||||
| 			action := CTSUploadAction{ | ||||
| 			action := UploadAction{ | ||||
| 				Connection:         connection, | ||||
| 				Application:        app, | ||||
| 				Node:               node, | ||||
| @@ -130,7 +130,7 @@ func TestUploadCTS(t *testing.T) { | ||||
| 			files = &filesMock | ||||
| 			defer func() { files = fMock }() | ||||
| 			cmd := mock.ShellMockRunner{} | ||||
| 			action := CTSUploadAction{ | ||||
| 			action := UploadAction{ | ||||
| 				Connection:         connection, | ||||
| 				Application:        app, | ||||
| 				Node:               node, | ||||
| @@ -146,7 +146,7 @@ func TestUploadCTS(t *testing.T) { | ||||
| 		}) | ||||
| 		t.Run("Config file missing", func(t *testing.T) { | ||||
| 			cmd := mock.ShellMockRunner{} | ||||
| 			action := CTSUploadAction{ | ||||
| 			action := UploadAction{ | ||||
| 				Connection:         connection, | ||||
| 				Application:        app, | ||||
| 				Node:               node, | ||||
		Reference in New Issue
	
	Block a user