mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
17de9ed34c
* Allow cALM service keys * Fix typo Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com> * fix typo Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com> * Hardcode tms endpoint in calm test case * Add new serviceKey parameter * Use new serviceKey parameter With deprecation warning if old tmsServiceKey parameter is used * Add unit tests and optimise * Remove tms from service key log message * Apply suggestions from code review Co-authored-by: Artem Bannikov <62880541+artembannikov@users.noreply.github.com> * Remove unused json fields mapping * Apply review suggestion * Apply further review suggestions * Use new parameter name in groovy * Generate again * Fix groovy test --------- Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com> Co-authored-by: Artem Bannikov <62880541+artembannikov@users.noreply.github.com>
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package tms
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func Test_unmarshalServiceKey(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
serviceKeyJson string
|
|
wantTmsUrl string
|
|
errMessage string
|
|
}{
|
|
{
|
|
name: "standard cTMS service key uri works",
|
|
serviceKeyJson: `{"uri": "https://my.tms.endpoint.sap.com"}`,
|
|
wantTmsUrl: "https://my.tms.endpoint.sap.com",
|
|
},
|
|
{
|
|
name: "standard cALM service key uri has expected postfix",
|
|
serviceKeyJson: `{"endpoints": {"Api": "https://my.alm.endpoint.sap.com"}}`,
|
|
wantTmsUrl: "https://my.alm.endpoint.sap.com/imp-cdm-transport-management-api/v1",
|
|
},
|
|
{
|
|
name: "no uri or endpoints in service key leads to error",
|
|
serviceKeyJson: `{"missing key options": "leads to error"}`,
|
|
errMessage: "neither uri nor endpoints.Api is set in service key json string",
|
|
},
|
|
{
|
|
name: "faulty json leads to error",
|
|
serviceKeyJson: `"this is not correct json"`,
|
|
errMessage: "json: cannot unmarshal string into Go value of type tms.serviceKey",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotServiceKey, err := unmarshalServiceKey(tt.serviceKeyJson)
|
|
if tt.errMessage == "" {
|
|
assert.NoError(t, err, "No error was expected")
|
|
assert.Equal(t, tt.wantTmsUrl, gotServiceKey.Uri, "Expected tms url does not match the uri in the service key")
|
|
} else {
|
|
assert.EqualError(t, err, tt.errMessage, "Error message not as expected")
|
|
}
|
|
})
|
|
}
|
|
}
|