-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration_test.go
145 lines (118 loc) · 5.17 KB
/
integration_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
141
142
143
144
145
//go:build integration
// +build integration
package gocd
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestCreatePipeline(t *testing.T) {
c := New("http://localhost:8153", "", "")
pipelineGroupName := "first"
pipelineGroup := PipelineGroup{
Name: pipelineGroupName,
}
pipelineGroupResponse, etag, err := c.CreatePipelineGroup(pipelineGroup)
require.Empty(t, err, "create pipeline group should not have thrown an error")
require.Equal(t, pipelineGroup.Name, pipelineGroupResponse.Name, "unexpected pipeline group name on creation")
pipelineGroupName = "second"
pipelineGroupResponse.Name = pipelineGroupName
pipelineGroupResponse2, _, err := c.UpdatePipelineGroup(pipelineGroup.Name, etag, pipelineGroupResponse)
require.Empty(t, err, "update pipeline group should not have thrown an error")
require.Equal(t, pipelineGroupName, pipelineGroupResponse2.Name, "unexpected pipeline group name on update")
pipelineGroups, err := c.GetAllPipelineGroups()
require.Empty(t, err, "get all pipeline groups should not have thrown an error")
require.Equal(t, 1, len(pipelineGroups), "unexpected number of pipeline groups")
pipelineName := "pipeline"
pipelineTask := PipelineTask{
Type: "exec",
Attributes: &PipelineTaskAttributes{
Command: "echo",
Arguments: []string{"1"},
},
}
pipelineJob := PipelineJob{
Name: "job1",
}
pipelineJob.AddTask(pipelineTask)
pipelineStage := PipelineStage{
Name: "stage1",
}
pipelineStage.AddJob(pipelineJob)
materialBranch := "main"
material := Material{
Type: "git",
Attributes: &MaterialAttributes{
Name: "go-gocd",
Url: "https://github.com/rcjames/go-gocd",
Branch: materialBranch,
ShallowClone: true,
},
}
pipeline := Pipeline{
Name: pipelineName,
Group: pipelineGroupName,
}
pipeline.AddStage(pipelineStage)
pipeline.AddMaterial(material)
pipelineResponse, pipelineEtag, err := c.CreatePipeline(pipeline)
require.Empty(t, err, "create pipeline should not have thrown an error")
require.Equal(t, pipelineName, pipelineResponse.Name, "unexpected pipeline name")
require.Equal(t, materialBranch, pipelineResponse.Materials[0].Attributes.Branch, "unexpected meterial branch")
updatedPipelineStageName := "stageA"
pipelineResponse.Stages[0].Name = updatedPipelineStageName
pipelineResponse2, _, err := c.UpdatePipeline(pipelineResponse.Name, pipelineEtag, pipelineResponse)
require.Empty(t, err, "update pipeline should not have thrown an error")
require.Equal(t, updatedPipelineStageName, pipelineResponse2.Stages[0].Name, "updated pipeline stage name is not expected")
msg, err := c.DeletePipeline(pipelineName)
require.Empty(t, err, "delete pipeline should not have thown an error")
want := fmt.Sprintf("Pipeline with name '%s' was deleted successfully!", pipelineName)
require.Equal(t, want, msg, "unexpected message when deleting pipeline")
msg, err = c.DeletePipelineGroup(pipelineGroupName)
require.Empty(t, err, "delete pipeline group should not have thrown an error")
want = fmt.Sprintf("Pipeline group with name '%s' was deleted successfully!", pipelineGroupName)
require.Equal(t, want, msg, "unexpected message when deleting pipeline group")
pipelineGroups, err = c.GetAllPipelineGroups()
require.Empty(t, err, "get all pipeline groups should not have thrown an error")
require.Equal(t, 0, len(pipelineGroups), "unexpected number of pipeline groups after delete")
}
func TestCreateArtifactStore(t *testing.T) {
c := New("http://localhost:8153", "", "")
artifactStoreId := "docker"
artifactStore := ArtifactStore{
Id: artifactStoreId,
PluginId: "cd.go.artifact.docker.registry",
}
var properties = make(map[string]string)
properties["RegistryURL"] = "https://your_docker_registry_url"
properties["Username"] = "admin"
properties["Password"] = "badger"
properties["RegistryType"] = "other"
for k, v := range properties {
p := ConfigurationProperty{
Key: k,
Value: v,
}
artifactStore.AddProperty(p)
}
artifactStoreResponse, etag, err := c.CreateArtifactStore(artifactStore)
require.Empty(t, err, "create artifact store should not have thrown an error")
require.Equal(t, artifactStoreId, artifactStoreResponse.Id, "unexpected artifact store id")
artifactStores, err := c.GetAllArtifactStores()
require.Empty(t, err, "get all artifact stores should not have thrown an error")
require.Equal(t, 1, len(artifactStores), "unexpected number of artifact stores")
var usernameKey int
for i, p := range artifactStoreResponse.Properties {
if p.Key == "Username" {
usernameKey = i
}
}
artifactStoreResponse.Properties[usernameKey].Value = "root"
artifactStoreResponse2, _, err := c.UpdateArtifactStore(artifactStoreId, etag, artifactStoreResponse)
require.Empty(t, err, "update artifact store should not have thrown an error")
require.Equal(t, "root", artifactStoreResponse2.GetPropertyValue("Username"), "unexpected registry password")
msg, err := c.DeleteArtifactStore(artifactStoreId)
require.Empty(t, err, "delete artifact store should not have thrown an error")
want := fmt.Sprintf("Artifact store with id '%s' was deleted successfully!", artifactStoreId)
require.Equal(t, want, msg, "unexpected message when deleting artifact store")
}