-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportextensions_test.go
102 lines (88 loc) · 2.59 KB
/
importextensions_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetOperationType(t *testing.T) {
type testCase struct {
name string
entity entity
data Import
want operationType
}
tests := []testCase{
{name: "Get operation for Token", entity: tokenEntity, data: getTestImport(), want: getOperation},
{name: "Put operation for Token", entity: tokenEntity, data: getTestImportWithoutTokenID(), want: putOperation},
{name: "Get operation for Project", entity: projectEntity, data: getTestImport(), want: getOperation},
{name: "Put operation for Project", entity: projectEntity, data: getTestImportWithoutProjectID(), want: putOperation},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, tc.data.getOperationType(tc.entity))
})
}
}
func TestWhatToImport(t *testing.T) {
type testCase struct {
name string
data Import
want importType
}
tests := []testCase{
{name: "Import project when group and project set", data: getTestImport(), want: importProject},
{name: "Import group when group set without project", data: getTestImportWithoutProject(), want: importGroup},
{name: "Import all groups when no group and no project set",
data: getTestImportWithoutGroupAndProject(), want: importAllGroups},
{name: "Invalid import when project set without group", data: getInvalidImport(), want: invalidImport},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, tc.data.whatToImport())
})
}
}
func getTestImportWithoutTokenID() Import {
importData := getTestImport()
importData.TokenID = 0
return importData
}
func getTestImportWithoutProjectID() Import {
importData := getTestImport()
importData.ProjectID = 0
return importData
}
func getTestImportWithoutGroupAndProject() Import {
importData := getTestImport()
importData.Group = ""
importData.Project = ""
return importData
}
func getInvalidImport() Import {
importData := getTestImport()
importData.Group = ""
return importData
}
func getTestImportWithoutProject() Import {
importData := getTestImport()
importData.Project = ""
return importData
}
func getTestImportWithNonExistentProjectID() Import {
importData := getTestImport()
importData.ProjectID = uint(10000000)
return importData
}
func getTestImport() Import {
importSampleData := Import{
TokenID: 256,
Token: "sample token",
User: "sample user name",
URL: "https://sth.com",
UploadURL: "",
ProviderID: 1,
ProjectID: 267,
Project: "sample project name",
Group: "sample group name",
}
return importSampleData
}