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 ==================================================================================
27 var helmStatusOutput = `
28 LAST DEPLOYED: Sat Mar 9 06:50:45 2019
34 NAME READY STATUS RESTARTS AGE
35 dummy-xapp-8984fc9fd-bkcbp 1/1 Running 0 55m
36 dummy-xapp-8984fc9fd-l6xch 1/1 Running 0 55m
37 dummy-xapp-8984fc9fd-pp4hg 1/1 Running 0 55m
40 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
41 dummy-xapp-dummy-xapp-chart ClusterIP 10.102.184.212 <none> 80/TCP 55m
43 ==> v1beta1/Deployment
44 NAME READY UP-TO-DATE AVAILABLE AGE
45 dummy-xapp 3/3 3 3 55m
48 var helListOutput = `Next: ""
51 Chart: dummy-xapp-chart-0.1.0
56 Updated: Mon Mar 11 06:55:05 2019
58 Chart: dummy-xapp-chart-0.1.0
63 Updated: Mon Mar 11 06:55:05 2019
70 Updated: Sun Mar 24 07:17:00 2019`
74 func TestHelmStatus(t *testing.T) {
76 KubectlExec = func(args string) (out []byte, err error) {
77 return []byte("10.102.184.212"), nil
79 xapp, err := h.ParseStatus("dummy-xapp", helmStatusOutput)
81 t.Errorf("Helm install failed: %v", err)
87 if !reflect.DeepEqual(xapp, x) {
88 t.Errorf("\n%v \n%v", xapp, x)
92 func TestHelmLists(t *testing.T) {
93 names, err := h.GetNames(helListOutput)
95 t.Errorf("Helm status failed: %v", err)
98 if !reflect.DeepEqual(names, []string{"dummy-xapp", "dummy-xapp2"}) {
99 t.Errorf("Helm status failed: %v", err)
103 func TestAddTillerEnv(t *testing.T) {
104 if addTillerEnv() != nil {
105 t.Errorf("TestAddTillerEnv failed!")
109 func TestGetInstallArgs(t *testing.T) {
110 x := XappDeploy{Name: "dummy-xapp", Namespace: "ricxapp"}
112 expectedArgs := "install helm-repo/dummy-xapp --name=dummy-xapp --namespace=ricxapp"
113 if args := getInstallArgs(x, false); args != expectedArgs {
114 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
117 x.ImageRepo = "localhost:5000"
118 expectedArgs = expectedArgs + " --set global.repository=" + "localhost:5000"
119 if args := getInstallArgs(x, false); args != expectedArgs {
120 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
123 x.ServiceName = "xapp"
124 expectedArgs = expectedArgs + " --set ricapp.service.name=" + "xapp"
125 if args := getInstallArgs(x, false); args != expectedArgs {
126 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
129 x.ServiceName = "xapp"
130 expectedArgs = expectedArgs + " --set ricapp.appconfig.override=dummy-xapp-appconfig"
131 if args := getInstallArgs(x, true); args != expectedArgs {
132 t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
136 func getXappData() (x Xapp) {
137 x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "10.102.184.212", "4560")
138 x.Instances = append(x.Instances, x.Instances[0])
139 x.Instances = append(x.Instances, x.Instances[0])
140 x.Instances[1].Name = "dummy-xapp-8984fc9fd-l6xch"
141 x.Instances[2].Name = "dummy-xapp-8984fc9fd-pp4hg"