-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathconversion_test.go
94 lines (76 loc) · 2.64 KB
/
conversion_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
package httpapi
import (
"fmt"
"testing"
"time"
argoV1aplha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/google/go-cmp/cmp"
)
func TestPipelinesToAppsResponse(t *testing.T) {
raw := parseYAMLToConfig(t, "testdata/pipelines.yaml")
apps := pipelinesToAppsResponse(raw)
want := &appsResponse{
Apps: []appResponse{
{
Name: "taxi", RepoURL: "https://example.com/demo/gitops.git",
Environments: []string{"dev"},
SyncStatus: nil,
LastDeployed: nil,
},
},
}
if diff := cmp.Diff(want, apps); diff != "" {
t.Fatalf("failed to parse:\n%s", diff)
}
}
func TestApplicationsToAppsResponse(t *testing.T) {
var apps []*argoV1aplha1.Application
app, _ := testArgoApplication("testdata/application.yaml")
apps = append(apps, app)
want := &appsResponse{
Apps: []appResponse{
{
Name: "test-app",
RepoURL: "https://github.com/test-repo/gitops.git",
Environments: []string{"dev"},
SyncStatus: []string{"Synced"},
LastDeployed: []string{time.Date(2021, time.Month(5), 15, 2, 12, 13, 0, time.UTC).Local().String()},
},
},
}
resp := applicationsToAppsResponse(apps, "https://github.com/test-repo/gitops")
if diff := cmp.Diff(want, resp); diff != "" {
t.Fatal(fmt.Errorf("WANT[%v] != RECEIVED[%v], diff=%s", want, resp, diff))
}
resp = applicationsToAppsResponse(apps, "https://github.com/test-repo/gitops.git")
if diff := cmp.Diff(want, resp); diff != "" {
t.Fatal(fmt.Errorf("WANT[%v] != RECEIVED[%v], diff=%s", want, resp, diff))
}
}
func TestApplicationsToAppsResponseForTwoApps(t *testing.T) {
var apps []*argoV1aplha1.Application
app, _ := testArgoApplication("testdata/application.yaml")
apps = append(apps, app)
app2, _ := testArgoApplication("testdata/application2.yaml")
apps = append(apps, app2)
want := &appsResponse{
Apps: []appResponse{
{
Name: "test-app",
RepoURL: "https://github.com/test-repo/gitops.git",
Environments: []string{"dev", "production"},
SyncStatus: []string{"Synced", "OutOfSync"},
LastDeployed: []string{time.Date(2021, time.Month(5), 15, 2, 12, 13, 0, time.UTC).Local().String(),
time.Date(2021, time.Month(5), 16, 1, 10, 35, 0, time.UTC).Local().String()},
},
},
}
resp := applicationsToAppsResponse(apps, "https://github.com/test-repo/gitops")
if diff := cmp.Diff(want, resp); diff != "" {
t.Fatal(fmt.Errorf("WANT[%v] != RECEIVED[%v], diff=%s", want, resp, diff))
}
resp = applicationsToAppsResponse(apps, "https://github.com/test-repo/gitops.git")
if diff := cmp.Diff(want, resp); diff != "" {
t.Fatal(fmt.Errorf("WANT[%v] != RECEIVED[%v], diff=%s", want, resp, diff))
}
}