1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/integrationArtifactResource_test.go
Mayur Belur Mohan 2d412d9f3c
IntegrationArtifactResource Command (#3027)
* IntegrationArtifactResource Command

* Remove unused code

* Formatting fix

* formatting fix

* formatting fix

* formatting fix

* formatting fix

* CodeReview Fixes

* Code Review Fix

* Code Review Fixes

* Code Review Fixes

* Format fix

* format fix

* format fix

* format fix

* Code Review Fix

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
2021-08-12 09:11:02 +02:00

138 lines
3.7 KiB
Go

package cmd
import (
"path/filepath"
"testing"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/stretchr/testify/assert"
)
func TestRunIntegrationArtifactResource(t *testing.T) {
t.Parallel()
t.Run("Create Resource Test", func(t *testing.T) {
filesMock := mock.FilesMock{}
path := filepath.Join("tempDir", "demo.xsl")
filesMock.AddFile(path, []byte("dummy content"))
exists, err := filesMock.FileExists(path)
assert.NoError(t, err)
assert.True(t, exists)
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactResourceOptions{
APIServiceKey: apiServiceKey,
IntegrationFlowID: "flow1",
Operation: "create",
ResourcePath: path,
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactResourceCreate", ResponseBody: ``, TestType: "Positive"}
// test
err = runIntegrationArtifactResource(&config, nil, &filesMock, &httpClient)
// assert
assert.NoError(t, err)
})
t.Run("Update Resource Test", func(t *testing.T) {
filesMock := mock.FilesMock{}
path := filepath.Join("tempDir", "demo.xsl")
filesMock.AddFile(path, []byte("dummy content"))
exists, err := filesMock.FileExists(path)
assert.NoError(t, err)
assert.True(t, exists)
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactResourceOptions{
APIServiceKey: apiServiceKey,
IntegrationFlowID: "flow1",
Operation: "update",
ResourcePath: path,
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactResourceUpdate", ResponseBody: ``, TestType: "Positive"}
// test
err = runIntegrationArtifactResource(&config, nil, &filesMock, &httpClient)
// assert
assert.NoError(t, err)
})
t.Run("Delete Resource Test", func(t *testing.T) {
filesMock := mock.FilesMock{}
path := filepath.Join("tempDir", "demo.xsl")
filesMock.AddFile(path, []byte("dummy content"))
exists, err := filesMock.FileExists(path)
assert.NoError(t, err)
assert.True(t, exists)
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactResourceOptions{
APIServiceKey: apiServiceKey,
IntegrationFlowID: "flow1",
Operation: "delete",
ResourcePath: path,
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactResourceDelete", ResponseBody: ``, TestType: "Positive"}
// test
err = runIntegrationArtifactResource(&config, nil, &filesMock, &httpClient)
// assert
assert.NoError(t, err)
})
t.Run("Create Resource Negative Test", func(t *testing.T) {
filesMock := mock.FilesMock{}
path := filepath.Join("tempDir", "demo.xsl")
filesMock.AddFile(path, []byte("dummy content"))
exists, err := filesMock.FileExists(path)
assert.NoError(t, err)
assert.True(t, exists)
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactResourceOptions{
APIServiceKey: apiServiceKey,
IntegrationFlowID: "flow1",
Operation: "create",
ResourcePath: path,
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactResourceCreate", ResponseBody: ``, TestType: "Negative"}
// test
err = runIntegrationArtifactResource(&config, nil, &filesMock, &httpClient)
// assert
assert.Error(t, err)
})
}