Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit fbf4d40

Browse files
authored
refactor data repository (#51)
add more tests
1 parent 10eaad5 commit fbf4d40

File tree

9 files changed

+66
-23
lines changed

9 files changed

+66
-23
lines changed

cmd/tools/cli/integration_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,47 @@ func TestDelete(t *testing.T) {
4646
}
4747
assertMessage(t, out.String(), `service "argo-server" deleted`)
4848
}
49+
50+
func TestLocalApply(t *testing.T) {
51+
cmd, out := setUp()
52+
cmd.SetArgs([]string{"apply", "argo-workflow-ns", "--kubectl", "--plugin-repo", joinWithRootData("plugins")})
53+
if err := cmd.Execute(); err != nil {
54+
t.Fatalf("unexpected error %v", err)
55+
}
56+
assertMessage(t, out.String(), `service/argo-server created`)
57+
}
58+
59+
func TestLocalDelete(t *testing.T) {
60+
cmd, out := setUp()
61+
cmd.SetArgs([]string{"delete", "argo-workflow-ns", "--kubectl", "--plugin-repo", joinWithRootData("plugins")})
62+
if err := cmd.Execute(); err != nil {
63+
t.Fatalf("unexpected error %v", err)
64+
}
65+
assertMessage(t, out.String(), `service "argo-server" deleted`)
66+
}
67+
68+
func TestLocalGroupApply(t *testing.T) {
69+
cmd, out := setUp()
70+
cmd.SetArgs([]string{"apply", "-g", "argo", "--kubectl", "--group-repo", joinWithRootData("groups")})
71+
if err := cmd.Execute(); err != nil {
72+
t.Fatalf("unexpected error %v", err)
73+
}
74+
assertMessage(t, out.String(), `service/argo-server created`)
75+
}
76+
77+
func TestLocalGroupDelete(t *testing.T) {
78+
cmd, out := setUp()
79+
cmd.SetArgs([]string{"delete", "-g", "argo", "--kubectl", "--group-repo", joinWithRootData("groups")})
80+
if err := cmd.Execute(); err != nil {
81+
t.Fatalf("unexpected error %v", err)
82+
}
83+
assertMessage(t, out.String(), `service "argo-server" deleted`)
84+
}
85+
86+
func getRootTestData() string {
87+
return "../../../local_repo/core/"
88+
}
89+
90+
func joinWithRootData(fileURI string) string {
91+
return getRootTestData() + fileURI
92+
}

internal/plugins/groups_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func TestValidatePluginsGroupSpec(t *testing.T) {
99
var group Group
10-
testPluginsGroupsSpec, err := group.Encode("testdata/groups/two_plugins/group.yaml")
10+
testPluginsGroupsSpec, err := group.Encode(joinWithRootData("groups/argo/group.yaml"))
1111

1212
if err != nil {
1313
t.Fatalf("failed to unmarshal test file: %s", err)

internal/plugins/plugins_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func TestValidate(t *testing.T) {
99
var p Plugin
10-
testPluginSpec, err := p.Encode("testdata/defaults/plugin.yaml")
10+
testPluginSpec, err := p.Encode(joinWithRootData("plugins/argo-workflow-ns/plugin.yaml"))
1111

1212
if err != nil {
1313
t.Fatal("failed to unmarshal test file")
@@ -28,7 +28,7 @@ func TestValidate(t *testing.T) {
2828

2929
func TestValidateDefaultValues(t *testing.T) {
3030
var p Plugin
31-
testPluginSpec, err := p.Encode("testdata/empty_defaults/plugin.yaml")
31+
testPluginSpec, err := p.Encode(joinWithRootData("plugins/argo-workflow-no-defaults/plugin.yaml"))
3232
if err != nil {
3333
t.Fatal("failed to unmarshal test file")
3434
}

internal/plugins/remote_contents_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func mockPluginsServer(t *testing.T, filePath string, contentType string) *httpt
2828
}
2929

3030
func TestPluginsList(t *testing.T) {
31-
var server = mockPluginsServer(t, "testdata/defaults/plugin.yaml", PluginType)
31+
var server = mockPluginsServer(t, joinWithRootData("plugins/argo-workflow-ns/plugin.yaml"), PluginType)
3232
defer server.Close()
3333
p, err := ContentList(server.URL)
3434
if err != nil {
@@ -40,7 +40,7 @@ func TestPluginsList(t *testing.T) {
4040
}
4141

4242
func TestPluginYamls(t *testing.T) {
43-
var server = mockPluginsServer(t, "testdata/defaults/plugin.yaml", PluginType)
43+
var server = mockPluginsServer(t, joinWithRootData("plugins/argo-workflow-ns/plugin.yaml"), PluginType)
4444
defer server.Close()
4545
var pluginList Plugins
4646

@@ -55,7 +55,7 @@ func TestPluginYamls(t *testing.T) {
5555
}
5656

5757
func TestGroupsYamls(t *testing.T) {
58-
var server = mockPluginsServer(t, "testdata/groups/two_plugins/group.yaml", GroupType)
58+
var server = mockPluginsServer(t, joinWithRootData("groups/argo/group.yaml"), GroupType)
5959
defer server.Close()
6060
var groups Groups
6161
r, err := groups.Encode(server.URL, "/test")

internal/plugins/shared_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package plugins
2+
3+
func getRootTestData() string {
4+
return "../../local_repo/core/"
5+
}
6+
7+
func joinWithRootData(fileURI string) string {
8+
return getRootTestData() + fileURI
9+
}

internal/plugins/testdata/empty_defaults/plugin.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

internal/plugins/testdata/groups/two_plugins/group.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
plugin-type: group
2+
group-name: only-argo
3+
plugins:
4+
- name: argo
5+
enabled: true

internal/plugins/testdata/defaults/plugin.yaml renamed to local_repo/core/plugins/argo-workflow-traefik/plugin.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ namespace: "argo"
33
yaml:
44
- url: "https://raw.githubusercontent.com/argoproj/argo/stable/manifests/namespace-install.yaml"
55
type: "file"
6+
- url: "https://raw.githubusercontent.com/kf5i/k3ai-plugins/main/common/traefik/argo-bind.yaml"
7+
type: "file"
68
bash:
79
- bashfile1
810
- bashfile2

0 commit comments

Comments
 (0)