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 TestHelmNamespace(t *testing.T) {
103 if getNamespace("pltxapp") != "pltxapp" {
104 t.Errorf("getNamespace failed!")
107 if getNamespace("") != "ricxapp" {
108 t.Errorf("getNamespace failed!")
112 func TestAddTillerEnv(t *testing.T) {
113 if addTillerEnv() != nil {
114 t.Errorf("TestAddTillerEnv failed!")
118 func TestGetInstallArgs(t *testing.T) {
119 x := XappDeploy{Name: "dummy-xapp"}
121 expectedArgs := "install helm-repo/dummy-xapp --name=dummy-xapp --namespace=ricxapp"
122 if args := getInstallArgs(x, false); args != expectedArgs {
123 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
126 x.ImageRepo = "localhost:5000"
127 expectedArgs = expectedArgs + " --set image.repository=" + "localhost:5000"
128 if args := getInstallArgs(x, false); args != expectedArgs {
129 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
132 x.ServiceName = "xapp"
133 expectedArgs = expectedArgs + " --set service.name=" + "xapp"
134 if args := getInstallArgs(x, false); args != expectedArgs {
135 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
138 x.ServiceName = "xapp"
139 expectedArgs = expectedArgs + " --set appconfig.override=true"
140 if args := getInstallArgs(x, true); args != expectedArgs {
141 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
145 func getXappData() (x Xapp) {
146 x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "10.102.184.212", "80")
147 x.Instances = append(x.Instances, x.Instances[0])
148 x.Instances = append(x.Instances, x.Instances[0])
149 x.Instances[1].Name = "dummy-xapp-8984fc9fd-l6xch"
150 x.Instances[2].Name = "dummy-xapp-8984fc9fd-pp4hg"