-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathpipelinessources_test.go
60 lines (54 loc) · 1.99 KB
/
pipelinessources_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
package tests
import (
"github.com/jfrog/jfrog-client-go/pipelines/services"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/stretchr/testify/assert"
"testing"
)
func TestPipelinesSources(t *testing.T) {
initPipelinesTest(t)
t.Run("addPipelineSource", testAddPipelineSource)
}
func testAddPipelineSource(t *testing.T) {
if *PipelinesVcsToken == "" {
assert.NotEmpty(t, *PipelinesVcsToken, "cannot run pipelines tests without vcs token configured")
return
}
// Create integration with provided token.
integrationName := getUniqueIntegrationName(services.GithubName)
integrationId, err := testsPipelinesIntegrationsService.CreateGithubIntegration(integrationName, *PipelinesVcsToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, integrationId)
// Create source with the above integration and assert.
sourceId, err := testsPipelinesSourcesService.AddSource(integrationId, *PipelinesVcsRepoFullPath, *PipelinesVcsBranch, services.DefaultPipelinesFileFilter, "")
if !assert.NoError(t, err) {
return
}
defer deleteSourceAndAssert(t, sourceId)
getSourceAndAssert(t, sourceId, integrationId)
}
func getSourceAndAssert(t *testing.T, sourceId, intId int) {
source, err := testsPipelinesSourcesService.GetSource(sourceId)
if !assert.NoError(t, err) {
return
}
assert.NotNil(t, source)
assert.Equal(t, intId, source.ProjectIntegrationId)
assert.Equal(t, *PipelinesVcsRepoFullPath, source.RepositoryFullName)
assert.Equal(t, *PipelinesVcsBranch, source.Branch)
assert.Equal(t, services.DefaultPipelinesFileFilter, source.FileFilter)
}
func deleteSourceAndAssert(t *testing.T, id int) {
pollingExecutor := &utils.RetryExecutor{
MaxRetries: 10,
RetriesIntervalMilliSecs: 3000,
ErrorMessage: "Failed deleting source. Trying again after sleep...",
ExecutionHandler: func() (shouldRetry bool, err error) {
err = testsPipelinesSourcesService.DeleteSource(id)
return err != nil, err
},
}
assert.NoError(t, pollingExecutor.Execute())
}