-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathedit_project_test.go
More file actions
116 lines (111 loc) · 3.88 KB
/
edit_project_test.go
File metadata and controls
116 lines (111 loc) · 3.88 KB
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
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package cmd
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestEditProject(t *testing.T) {
tt := []struct {
name string
flagsMap map[string]string
args []string
expect testResult
}{
{
name: "edit an existing project using all flags",
flagsMap: map[string]string{
"desc": "Updated by go test",
"issues-enabled": "false",
"merge-requests-enabled": "false",
"jobs-enabled": "false",
"wiki-enabled": "false",
"snippets-enabled": "false",
"resolve-outdated-diff-discussions": "false",
"container-registry-enabled": "false",
"shared-runners-enabled": "false",
"visibility": "private",
"public-jobs": "false",
"only-allow-merge-if-pipeline-succeeds": "true",
"only-allow-merge-if-discussion-are-resolved": "true",
"merge-method": "ff",
"lfs-enabled": "false",
"request-access-enabled": "false",
"tag-list": "patched,gotest,tdd",
"printing-merge-request-link-enabled": "true",
"ci-config-path": "xgitlabci.yml",
"out": "json",
},
args: []string{"Group2/project12"},
expect: pass,
},
{
name: "update a project by id",
flagsMap: map[string]string{
"desc": "updated by using id",
"name": "Project 4",
"out": "json",
},
args: []string{"4"},
expect: pass,
},
{
name: "invalid visibility value should fail",
flagsMap: map[string]string{
"visibility": "xxxx",
},
args: []string{"ProjectY"},
expect: fail,
},
{
name: "invalid merge method value should fail",
flagsMap: map[string]string{
// fix the visibility value from above tc
"visibility": "private",
"merge-method": "xxxx",
},
args: []string{"ProjectZ"},
expect: fail,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
execT := execTestCmdFlags{
t: t,
cmd: editProjectCmd,
flagsMap: tc.flagsMap,
args: tc.args,
}
stdout, execResult := execT.executeCommand()
if tc.expect == fail {
tInfo(fmt.Sprintf("negative test result: %s", stdout))
}
require.Equal(t, tc.expect, execResult,
printFlagsTable(tc.flagsMap, stdout))
if tc.expect == pass {
tInfo(stdout)
require.Contains(t, stdout, tc.flagsMap["desc"],
printFlagsTable(tc.flagsMap,
fmt.Sprintf("Expecting to see '%s' in stdout",
tc.flagsMap["desc"])))
}
})
}
}