-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathpipelinesintegrations_test.go
140 lines (124 loc) · 4.95 KB
/
pipelinesintegrations_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package tests
import (
"github.com/jfrog/jfrog-client-go/pipelines/services"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
const (
integrationNamesPrefix = "jfrog_client_pipelines_integrations_tests"
testsDummyRtUrl = "https://pipelines.integration.com/artifactory/"
testsDummyVcsUrl = "https://non-existing-vcs.com/"
testsDummyUser = "nonexistinguser"
testsDummyToken = "nonexistingtoken"
testsDummyApiKey = "nonexistingkey"
)
func TestPipelinesIntegrations(t *testing.T) {
initPipelinesTest(t)
t.Run(services.GithubName, testCreateGithubIntegrationAndGetByName)
t.Run(services.GithubEnterpriseName, testCreateGithubEnterpriseIntegration)
t.Run(services.BitbucketName, testCreateBitbucketIntegration)
t.Run(services.BitbucketServerName, testCreateBitbucketServerIntegration)
t.Run(services.GitlabName, testCreateGitlabIntegration)
t.Run(services.ArtifactoryName, testCreateArtifactoryIntegration)
t.Run("GetAllIntegrations", getAllIntegrationAndAssert)
}
func testCreateGithubIntegrationAndGetByName(t *testing.T) {
name := getUniqueIntegrationName(services.GithubName)
id, err := testsPipelinesIntegrationsService.CreateGithubIntegration(name, testsDummyToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)
getIntegrationAndAssert(t, id, name, services.GithubName)
// Test get by name.
integration, err := testsPipelinesIntegrationsService.GetIntegrationByName(name)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, name, integration.Name)
assert.Equal(t, id, integration.Id)
}
func testCreateGithubEnterpriseIntegration(t *testing.T) {
name := getUniqueIntegrationName(services.GithubEnterpriseName)
id, err := testsPipelinesIntegrationsService.CreateGithubEnterpriseIntegration(name, testsDummyVcsUrl, testsDummyToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)
getIntegrationAndAssert(t, id, name, services.GithubEnterpriseName)
}
func testCreateBitbucketIntegration(t *testing.T) {
name := getUniqueIntegrationName(services.BitbucketName)
id, err := testsPipelinesIntegrationsService.CreateBitbucketIntegration(name, testsDummyUser, testsDummyToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)
getIntegrationAndAssert(t, id, name, services.BitbucketName)
}
func testCreateBitbucketServerIntegration(t *testing.T) {
name := getUniqueIntegrationName(services.BitbucketServerName)
id, err := testsPipelinesIntegrationsService.CreateBitbucketServerIntegration(name, testsDummyVcsUrl, testsDummyUser, testsDummyToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)
getIntegrationAndAssert(t, id, name, services.BitbucketServerName)
}
func testCreateGitlabIntegration(t *testing.T) {
name := getUniqueIntegrationName(services.GitlabName)
id, err := testsPipelinesIntegrationsService.CreateGitlabIntegration(name, testsDummyVcsUrl, testsDummyToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)
getIntegrationAndAssert(t, id, name, services.GitlabName)
}
func testCreateArtifactoryIntegration(t *testing.T) {
name := getUniqueIntegrationName(services.ArtifactoryName)
id, err := testsPipelinesIntegrationsService.CreateArtifactoryIntegration(name, testsDummyRtUrl, testsDummyUser, testsDummyApiKey)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)
getIntegrationAndAssert(t, id, name, services.ArtifactoryName)
}
func getIntegrationAndAssert(t *testing.T, id int, name, integrationType string) {
integration, err := testsPipelinesIntegrationsService.GetIntegrationById(id)
if !assert.NoError(t, err) {
return
}
assert.NotNil(t, integration)
assert.Equal(t, name, integration.Name)
assert.Equal(t, integrationType, integration.MasterIntegrationName)
}
func getAllIntegrationAndAssert(t *testing.T) {
// Create Artifactory Integration
name := getUniqueIntegrationName(services.ArtifactoryName)
id, err := testsPipelinesIntegrationsService.CreateArtifactoryIntegration(name, testsDummyRtUrl, testsDummyUser, testsDummyApiKey)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)
// Create Gitlab Integration
name = getUniqueIntegrationName(services.GitlabName)
gitlabIntegrationId, err := testsPipelinesIntegrationsService.CreateGitlabIntegration(name, testsDummyVcsUrl, testsDummyToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, gitlabIntegrationId)
integrations, err := testsPipelinesIntegrationsService.GetAllIntegrations()
if !assert.NoError(t, err) {
return
}
assert.NotNil(t, integrations)
assert.True(t, len(integrations) > 2)
}
func getUniqueIntegrationName(integrationType string) string {
return strings.Join([]string{integrationNamesPrefix, integrationType, getCustomRunId('_')}, "_")
}
func deleteIntegrationAndAssert(t *testing.T, id int) {
err := testsPipelinesIntegrationsService.DeleteIntegration(id)
assert.NoError(t, err)
}