1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-11-06 09:09:19 +02:00
* it test

* transfer credentials

* Change parameter type of nodeExtDescriptorMapping

* Extend test

* Fix unit test

* Remove usage of the depricated ioutil package

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

* Extend test

* Add TMS test to the job matrix

* Map env. variable

* Remove usage of the env. TMS_UPLOAD_IT_KEY

* remove os

* update test

* use os.Gerenv

* test fix

* Update integration-tests.yml

* env mapping in it pr workflow

* print tmsServiceKey

* read env with upper case

* Update integration-tests.yml

* Update integration-tests.yml

* Update integration-tests-pr.yml

* Delete cover.out

* Remove TMS service key from environment in integration test workflow job

* Extend integration tests

* Revert change parameter type of nodeExtDescriptorMapping

* Extend tests

* Extend tests

* Remove unused method

* Change default TR description

* Add check for custom description

* Remove personal data from MTARs

* Register client secret to log as secret

* Move RegisterSecret to earlier point in runtime

* RegisterSecret for encodedUsernameColonPassword

* Update integration/integration_tms_upload_test.go

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>

* Use one test data directory

* Add a negative test

* fix config file name

---------

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
This commit is contained in:
gerstneralex
2023-03-07 17:49:28 +01:00
committed by GitHub
parent 22f61be2c4
commit cfe21ebb7e
9 changed files with 205 additions and 23 deletions

View File

@@ -19,6 +19,7 @@ run:
- '"TestMavenIntegration"'
- '"TestMTAIntegration"'
# - '"TestNexusIntegration"'
- '"TestTmsUploadIntegration"'
# these are light-weighted tests, so we can use only one pod to reduce resource consumption
- '"Test(Gauge|GCS|GitHub|GitOps|Influx|NPM|Piper|Python|Sonar|Vault|Karma)Integration"'

View File

@@ -0,0 +1,144 @@
//go:build integration
// +build integration
// can be executed with
// go test -v -tags integration -run TestTmsUploadIntegration ./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", "TestTmsUploadIntegration"},
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", "TestTmsUploadIntegration"},
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", "TestTmsUploadIntegration"},
})
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", "TestTmsUploadIntegration"},
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", "TestTmsUploadIntegration"},
Environment: map[string]string{"PIPER_tmsServiceKey": tmsServiceKey},
})
defer container.terminate(t)
err := container.whenRunningPiperCommand("tmsUpload", "--customConfig=.pipeline/tms_integration_test_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")
}

View File

@@ -0,0 +1,12 @@
general:
verbose: true
steps:
tmsUpload:
useGoStep: true
nodeName: PIPER-TEST
mtaPath: scv_x.mtar
verbose: true
mtaVersion: 1.0.0
nodeExtDescriptorMapping:
PIPER-TEST: 'scv_x.mtaext'
PIPER-PROD: 'scv_x.mtaext'

View File

@@ -0,0 +1,14 @@
_schema-version: "3.1.0"
ID: alm.pi.test.scv_x
version: 1.0.0
modules:
- name: java-hello-sap-x
type: java.tomcat
path: java/target/scv_x-1.0.0.war
properties:
API_URL: "${xs-api-url}"
SET_LOGGING_LEVEL: "{alm.pi.test: INFO}"
MEMORY_CALCULATOR_V1: true
parameters:
memory: 128MM

View File

@@ -0,0 +1,8 @@
_schema-version: "3.1.0"
ID: alm.pi.test.scv_x_ext
extends: alm.pi.test.scv_x
modules:
- name: java-hello-sap-x
parameters:
memory: 256M

Binary file not shown.