blob: e37b6d15b4222b0c468af1a9fa6ad8683c24e658 [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"
Scott Baker14c8f182019-05-22 18:05:29 -070021 "testing"
22)
23
24func TestVersionClientOnly(t *testing.T) {
25 expected := "" +
26 "Client:\n" +
27 " Version unknown-version\n" +
28 " Go version: unknown-goversion\n" +
29 " Git commit: unknown-gitcommit\n" +
30 " Git dirty: unknown-gitdirty\n" +
31 " Built: unknown-buildtime\n" +
32 " OS/Arch: unknown-os/unknown-arch\n" +
33 "\n"
34
35 got := new(bytes.Buffer)
36 OutputStream = got
37
38 var options VersionOpts
39 options.ClientOnly = true
40 err := options.Execute([]string{})
41
42 if err != nil {
43 t.Errorf("%s: Received error %v", t.Name(), err)
44 return
45 }
46
47 if got.String() != expected {
48 t.Logf("RECEIVED:\n%s\n", got.String())
49 t.Logf("EXPECTED:\n%s\n", expected)
50 t.Errorf("%s: expected and received did not match", t.Name())
51 }
52}
53
54func TestVersionClientAndServer(t *testing.T) {
55 expected := "" +
56 "Client:\n" +
57 " Version unknown-version\n" +
58 " Go version: unknown-goversion\n" +
59 " Git commit: unknown-gitcommit\n" +
60 " Git dirty: unknown-gitdirty\n" +
61 " Built: unknown-buildtime\n" +
62 " OS/Arch: unknown-os/unknown-arch\n" +
63 "\n" +
64 "Server:\n" +
65 " Version 3.2.6\n" +
66 " Python version: 2.7.16 (default, May 6 2019, 19:35:26)\n" +
Scott Baker87efa392019-06-18 17:09:46 -070067 " Django version: unknown\n" +
Scott Baker14c8f182019-05-22 18:05:29 -070068 " Git commit: b0df1bf6ed1698285eda6a6725c5da0c80aa4aee\n" +
69 " Built: 2019-05-20T17:04:14Z\n" +
70 " OS/Arch: linux/x86_64\n" +
71 "\n"
72
73 got := new(bytes.Buffer)
74 OutputStream = got
75
76 var options VersionOpts
77 err := options.Execute([]string{})
78
79 if err != nil {
80 t.Errorf("%s: Received error %v", t.Name(), err)
81 return
82 }
83
84 if got.String() != expected {
85 t.Logf("RECEIVED:\n%s\n", got.String())
86 t.Logf("EXPECTED:\n%s\n", expected)
87 t.Errorf("%s: expected and received did not match", t.Name())
88 }
89}