1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/integration/integration_tms_upload_test.go
gerstneralex f5c33d51bb
Tms export (#4160)
* Change parameter type of nodeExtDescriptorMapping

(cherry picked from commit ca7ce0485a)

* Remove usage of the depricated ioutil package

(cherry picked from commit 9821915b33)

* Fix cmd failure if neither git/commitId nor customDescription are
provided

(cherry picked from commit c362681e45)

* Fix unit test

(cherry picked from commit 53a90aabb5)

* Step metadata, step code generation

* change type of nodeExtDescriptorMapping for export

* Refactoring and export implementation

* integration test

* Add export step

* Integration test

* format

* discard piper.go

* Review related changes

* restore piper.go

* remove unused method

* Extend documentation

* Add parameter useGoStep to tmsUpload.groovy

* Regenerate steps

* Rename function

* refactor constants

* Add error path tests

* Move some code to tms package

* Move more code to tms

* Combine tmsUpload, tmsUtils

* Add groovy wrapper

* add parameters to groovy step

* add import

* jenkinsUtils instance

* comment namedUser logic in groovy

* namedUser param

* remove logic for namedUser param

* Remove TMS integration tests

* discard changes in tmsUpload.groovy

* Remove parameters

* Restore parameters

* Change type of NodeExtDescriptorMapping to map[string]interface{}

* tmsUpload: Change type of NodeExtDescriptorMapping to map

* Resolve ioutil deprecation

* Review related changes

* Formatting

* Review related improvements

* Add tmsUtils test

* Formatting tmsUtils_test

* Remove parameters from groovy wrapper

* Remove tmsUtils_test

* Add TMS steps to fieldRelatedWhitelist

* Add integration test

* Add test to github_actions_integration_test_list.yml

* Move test helper method

* Step documentation placeholder

* Remove parameter StashContent

* Restore cmd/integrationArtifactTransport.go

---------

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
2023-03-27 16:55:29 +02:00

145 lines
4.8 KiB
Go

//go:build integration
// +build integration
// can be executed with
// go test -v -tags integration -run TestTmsIntegration ./integration
package main
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
var tmsServiceKey string
func readEnv() {
//Reading TMS credentials from environment
tmsServiceKey = os.Getenv("PIPER_tmsServiceKey")
if len(tmsServiceKey) == 0 {
fmt.Println("Env. variable PIPER_tmsServiceKey is not provided")
os.Exit(1)
}
}
func TestTmsUploadIntegrationBinSuccess(t *testing.T) {
// success case: run cmd without nodeExtDescriptorMapping
readEnv()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "devxci/mbtci-java11-node14",
User: "root",
TestDir: []string{"testdata", "TestTmsIntegration"},
Environment: map[string]string{"PIPER_tmsServiceKey": tmsServiceKey},
})
defer container.terminate(t)
err := container.whenRunningPiperCommand("tmsUpload",
"--mtaPath=scv_x.mtar",
"--nodeName=PIPER-TEST",
"--customDescription=Piper integration test",
"--mtaVersion=1.0.0",
"-v")
if err != nil {
t.Fatalf("Piper command failed %s", err)
}
container.assertHasOutput(t, "description: Piper integration test")
container.assertHasOutput(t, "tmsUpload - File uploaded successfully")
container.assertHasOutput(t, "tmsUpload - Node upload executed successfully")
container.assertHasOutput(t, "tmsUpload - SUCCESS")
}
func TestTmsUploadIntegrationBinNoDescriptionSuccess(t *testing.T) {
// success case: run cmd without --nodeExtDescriptorMapping and --customDescription
readEnv()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "devxci/mbtci-java11-node14",
User: "root",
TestDir: []string{"testdata", "TestTmsIntegration"},
Environment: map[string]string{"PIPER_tmsServiceKey": tmsServiceKey},
})
defer container.terminate(t)
err := container.whenRunningPiperCommand("tmsUpload",
"--mtaPath=scv_x.mtar",
"--nodeName=PIPER-TEST",
"--mtaVersion=1.0.0",
"-v")
if err != nil {
t.Fatalf("Piper command failed %s", err)
}
container.assertHasOutput(t, "description: Created by Piper")
container.assertHasOutput(t, "tmsUpload - File uploaded successfully")
container.assertHasOutput(t, "tmsUpload - Node upload executed successfully")
container.assertHasOutput(t, "tmsUpload - SUCCESS")
}
func TestTmsUploadIntegrationBinFailParam(t *testing.T) {
// error case: run cmd with nodeExtDescriptorMapping
readEnv()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "devxci/mbtci-java11-node14",
User: "root",
TestDir: []string{"testdata", "TestTmsIntegration"},
})
defer container.terminate(t)
err := container.whenRunningPiperCommand("tmsUpload",
"--mtaPath=scv_x.mtar",
"--nodeName=PIPER-TEST",
"--customDescription=Piper integration test",
"--nodeExtDescriptorMapping={\"PIPER-TEST\":\"scv_x.mtaext\", \"PIPER-PROD\":\"scv_x.mtaext\"}",
"--mtaVersion=1.0.0",
"-v")
assert.Error(t, err, "Did expect error")
container.assertHasOutput(t, "Error: unknown flag: --nodeExtDescriptorMapping")
}
func TestTmsUploadIntegrationBinFailDescription(t *testing.T) {
// error case: run cmd with invalid description
readEnv()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "devxci/mbtci-java11-node14",
User: "root",
TestDir: []string{"testdata", "TestTmsIntegration"},
Environment: map[string]string{"PIPER_tmsServiceKey": tmsServiceKey},
})
defer container.terminate(t)
err := container.whenRunningPiperCommand("tmsUpload",
"--mtaPath=scv_x.mtar",
"--nodeName=PIPER-TEST",
"--customDescription={Bad description}")
assert.Error(t, err, "Did expect error")
container.assertHasOutput(t, "error tmsUpload - HTTP request failed with error")
container.assertHasOutput(t, "Failed to run tmsUpload step - failed to upload file to node")
}
func TestTmsUploadIntegrationYaml(t *testing.T) {
// success case: run with custom config
readEnv()
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
Image: "devxci/mbtci-java11-node14",
User: "root",
TestDir: []string{"testdata", "TestTmsIntegration"},
Environment: map[string]string{"PIPER_tmsServiceKey": tmsServiceKey},
})
defer container.terminate(t)
err := container.whenRunningPiperCommand("tmsUpload", "--customConfig=.pipeline/upload_config.yml")
if err != nil {
t.Fatalf("Piper command failed %s", err)
}
container.assertHasOutput(t, "tmsUpload - File uploaded successfully")
container.assertHasOutput(t, "tmsUpload - MTA extension descriptor updated successfully")
container.assertHasOutput(t, "tmsUpload - Node upload executed successfully")
container.assertHasOutput(t, "tmsUpload - SUCCESS")
// test that oauth token is not exposed
container.assertHasNoOutput(t, "eyJ")
}