blob: 04375bf351ca9d095259e8dba97f13a0ce55b65b [file] [log] [blame]
gioefa0ed42024-06-13 12:31:43 +04001package installer
2
3import (
4 "testing"
giof15b9da2024-09-19 06:59:16 +04005
6 "cuelang.org/go/cue"
gioefa0ed42024-06-13 12:31:43 +04007)
8
9func TestFindPortFields(t *testing.T) {
10 scm := structSchema{
11 "a",
12 []Field{
gio36b23b32024-08-25 12:20:54 +040013 Field{"x", basicSchema{"x", KindString, false, nil}},
14 Field{"y", basicSchema{"y", KindInt, false, nil}},
15 Field{"z", basicSchema{"z", KindPort, false, nil}},
gioefa0ed42024-06-13 12:31:43 +040016 Field{
17 "w",
18 structSchema{
19 "w",
20 []Field{
gio36b23b32024-08-25 12:20:54 +040021 Field{"x", basicSchema{"x", KindString, false, nil}},
22 Field{"y", basicSchema{"y", KindInt, false, nil}},
23 Field{"z", basicSchema{"z", KindPort, false, nil}},
gioefa0ed42024-06-13 12:31:43 +040024 },
25 false,
26 },
27 },
28 },
29 false,
30 }
31 p := findPortFields(scm)
32 if len(p) != 2 {
33 t.Fatalf("expected two port fields, %v", p)
34 }
35 if p[0] != "z" || p[1] != "w.z" {
36 t.Fatalf("expected 'z' and 'w.z' port fields, %v", p)
37 }
38}
giof15b9da2024-09-19 06:59:16 +040039
40const isNotNetwork = `
41input: {
42 repoAddr: string
43 repoPublicAddr: string
44 managerAddr: string
45 appId: string
46 branch: string
47 sshPrivateKey: string
48 username?: string
49 cluster: #Cluster
50 username?: string | *"test"
51 vpnAuthKey: string @role(VPNAuthKey) @usernameField(username)
52}
53
54#Cluster: {
55 name: string
56 kubeconfig: string
57 ingressClassName: string
58}
59`
60
61func TestIsNotNetwork(t *testing.T) {
62 v, err := ParseCueAppConfig(CueAppData{"/test.cue": []byte(isNotNetwork)})
63 if err != nil {
64 t.Fatal(err)
65 }
66 if isNetwork(v.LookupPath(cue.ParsePath("input"))) {
67 t.Fatal("not really network")
68 }
69}
70
71const inputIsNetwork = `
72input: {
73 name: string
74 ingressClass: string
75 certificateIssuer: string | *""
76 domain: string
77 allocatePortAddr: string
78 reservePortAddr: string
79 deallocatePortAddr: string
80}
81`
82
83func TestIsNetwork(t *testing.T) {
84 v, err := ParseCueAppConfig(CueAppData{"/test.cue": []byte(inputIsNetwork)})
85 if err != nil {
86 t.Fatal(err)
87 }
88 if !isNetwork(v.LookupPath(cue.ParsePath("input"))) {
89 t.Fatal("is network")
90 }
91}