blob: 1ebe7c30391dfb120a592425047ede20db7877b4 [file] [log] [blame]
Scott Baker14c8f182019-05-22 18:05:29 -07001/*
2 * Portions copyright 2019-present Open Networking Foundation
3 * Original copyright 2019-present Ciena Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package commands
18
19import (
20 "bytes"
21 "fmt"
22 "github.com/opencord/cordctl/testutils"
23 "os"
24 "testing"
25)
26
27func TestVersionClientOnly(t *testing.T) {
28 expected := "" +
29 "Client:\n" +
30 " Version unknown-version\n" +
31 " Go version: unknown-goversion\n" +
32 " Git commit: unknown-gitcommit\n" +
33 " Git dirty: unknown-gitdirty\n" +
34 " Built: unknown-buildtime\n" +
35 " OS/Arch: unknown-os/unknown-arch\n" +
36 "\n"
37
38 got := new(bytes.Buffer)
39 OutputStream = got
40
41 var options VersionOpts
42 options.ClientOnly = true
43 err := options.Execute([]string{})
44
45 if err != nil {
46 t.Errorf("%s: Received error %v", t.Name(), err)
47 return
48 }
49
50 if got.String() != expected {
51 t.Logf("RECEIVED:\n%s\n", got.String())
52 t.Logf("EXPECTED:\n%s\n", expected)
53 t.Errorf("%s: expected and received did not match", t.Name())
54 }
55}
56
57func TestVersionClientAndServer(t *testing.T) {
58 expected := "" +
59 "Client:\n" +
60 " Version unknown-version\n" +
61 " Go version: unknown-goversion\n" +
62 " Git commit: unknown-gitcommit\n" +
63 " Git dirty: unknown-gitdirty\n" +
64 " Built: unknown-buildtime\n" +
65 " OS/Arch: unknown-os/unknown-arch\n" +
66 "\n" +
67 "Server:\n" +
68 " Version 3.2.6\n" +
69 " Python version: 2.7.16 (default, May 6 2019, 19:35:26)\n" +
70 " Git commit: b0df1bf6ed1698285eda6a6725c5da0c80aa4aee\n" +
71 " Built: 2019-05-20T17:04:14Z\n" +
72 " OS/Arch: linux/x86_64\n" +
73 "\n"
74
75 got := new(bytes.Buffer)
76 OutputStream = got
77
78 var options VersionOpts
79 err := options.Execute([]string{})
80
81 if err != nil {
82 t.Errorf("%s: Received error %v", t.Name(), err)
83 return
84 }
85
86 if got.String() != expected {
87 t.Logf("RECEIVED:\n%s\n", got.String())
88 t.Logf("EXPECTED:\n%s\n", expected)
89 t.Errorf("%s: expected and received did not match", t.Name())
90 }
91}
92
93func TestMain(m *testing.M) {
94 err := testutils.StartMockServer("data.json")
95 if err != nil {
96 fmt.Printf("Error when initializing mock server %v", err)
97 os.Exit(-1)
98 }
99 os.Exit(m.Run())
100}