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
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

141 lines
3.7 KiB
Go

//go:build unit
// +build unit
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)
})
}