2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
28 var helmStatusOutput = `
29 LAST DEPLOYED: Sat Mar 9 06:50:45 2019
35 NAME READY STATUS RESTARTS AGE
36 dummy-xapp-8984fc9fd-bkcbp 1/1 Running 0 55m
37 dummy-xapp-8984fc9fd-l6xch 1/1 Running 0 55m
38 dummy-xapp-8984fc9fd-pp4hg 1/1 Running 0 55m
41 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
42 dummy-xapp-dummy-xapp-chart ClusterIP 10.102.184.212 <none> 80/TCP 55m
44 ==> v1beta1/Deployment
45 NAME READY UP-TO-DATE AVAILABLE AGE
46 dummy-xapp 3/3 3 3 55m
49 var helListOutput = `Next: ""
52 Chart: dummy-xapp-chart-0.1.0
57 Updated: Mon Mar 11 06:55:05 2019
59 Chart: dummy-xapp-chart-0.1.0
64 Updated: Mon Mar 11 06:55:05 2019
71 Updated: Sun Mar 24 07:17:00 2019`
76 func TestHelmStatus(t *testing.T) {
78 xapp, err := h.ParseStatus("dummy-xapp", helmStatusOutput)
80 t.Errorf("Helm install failed: %v", err)
86 if !reflect.DeepEqual(xapp, x) {
87 t.Errorf("\n%v \n%v", xapp, x)
91 func TestHelmLists(t *testing.T) {
92 names, err := h.GetNames(helListOutput)
94 t.Errorf("Helm status failed: %v", err)
97 if !reflect.DeepEqual(names, []string{"dummy-xapp", "dummy-xapp2"}) {
98 t.Errorf("Helm status failed: %v", err)
102 func TestAddTillerEnv(t *testing.T) {
103 if addTillerEnv() != nil {
104 t.Errorf("TestAddTillerEnv failed!")
108 func TestGetInstallArgs(t *testing.T) {
109 x := XappDeploy{Name: "dummy-xapp", Namespace: "ricxapp"}
111 expectedArgs := "install helm-repo/dummy-xapp --name=dummy-xapp --namespace=ricxapp"
112 if args := getInstallArgs(x, false); args != expectedArgs {
113 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
116 x.ImageRepo = "localhost:5000"
117 expectedArgs = expectedArgs + " --set global.repository=" + "localhost:5000"
118 if args := getInstallArgs(x, false); args != expectedArgs {
119 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
122 x.ServiceName = "xapp"
123 expectedArgs = expectedArgs + " --set ricapp.service.name=" + "xapp"
124 if args := getInstallArgs(x, false); args != expectedArgs {
125 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
128 x.ServiceName = "xapp"
129 expectedArgs = expectedArgs + " --set ricapp.appconfig.override=dummy-xapp-appconfig"
130 if args := getInstallArgs(x, true); args != expectedArgs {
131 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
135 func getXappData() (x Xapp) {
136 x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "10.102.184.212", "80")
137 x.Instances = append(x.Instances, x.Instances[0])
138 x.Instances = append(x.Instances, x.Instances[0])
139 x.Instances[1].Name = "dummy-xapp-8984fc9fd-l6xch"
140 x.Instances[2].Name = "dummy-xapp-8984fc9fd-pp4hg"