-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
106 lines (88 loc) · 2.49 KB
/
main_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
package main
import (
"bytes"
"context"
"fmt"
"io"
"os"
"testing"
"github.com/ivanklee86/argonap/pkg/client"
"github.com/stretchr/testify/assert"
)
func TestRoot(t *testing.T) {
argoCDClient := client.CreateTestClient("./.env")
t.Run("Root command", func(t *testing.T) {
b := bytes.NewBufferString("")
command := NewRootCommand()
command.SetOut(b)
command.SetArgs([]string{
"--server-address", "localhost:8080",
"--insecure",
"--auth-token", os.Getenv("ARGOCD_TOKEN"),
})
err := command.Execute()
if err != nil {
t.Fatal(err)
}
out, err := io.ReadAll(b)
if err != nil {
t.Fatal(err)
}
assert.Contains(t, string(out), "argonap")
})
t.Run("Run clear command", func(t *testing.T) {
appProjects := client.GenerateTestProjects("./.env")
defer client.DeleteTestProjects(appProjects, "./.env")
b := bytes.NewBufferString("")
command := NewRootCommand()
command.SetOut(b)
command.SetArgs([]string{
"clear",
"--server-address", "localhost:8080",
"--name", appProjects[0].ObjectMeta.Name,
"--name", appProjects[1].ObjectMeta.Name,
"--name", appProjects[2].ObjectMeta.Name,
"--insecure",
"--auth-token", os.Getenv("ARGOCD_TOKEN"),
})
err := command.Execute()
assert.Nil(t, err)
assert.Nil(t, err)
for _, appProject := range appProjects {
updatedAppProject, _ := argoCDClient.GetProject(context.TODO(), appProject.Name)
assert.Nil(t, updatedAppProject.Spec.SyncWindows)
}
out, err := io.ReadAll(b)
assert.Nil(t, err)
fmt.Sprintln(string(out))
})
t.Run("Run set command", func(t *testing.T) {
appProjects := client.GenerateTestProjects("./.env")
defer client.DeleteTestProjects(appProjects, "./.env")
b := bytes.NewBufferString("")
command := NewRootCommand()
command.SetOut(b)
command.SetArgs([]string{
"set",
"--server-address", "localhost:8080",
"--insecure",
"--auth-token", os.Getenv("ARGOCD_TOKEN"),
"--name", appProjects[0].ObjectMeta.Name,
"--name", appProjects[1].ObjectMeta.Name,
"--name", appProjects[2].ObjectMeta.Name,
"--file", "./integration/exampleSyncWindows.json",
"--label", "env=dev",
})
err := command.Execute()
assert.Nil(t, err)
assert.Nil(t, err)
for index, appProject := range appProjects {
updatedAppProject, _ := argoCDClient.GetProject(context.TODO(), appProject.Name)
if index == 1 { // SyncWindow already exists
assert.Len(t, updatedAppProject.Spec.SyncWindows, 3)
} else {
assert.Len(t, updatedAppProject.Spec.SyncWindows, 2)
}
}
})
}