Scott Baker | 14c8f18 | 2019-05-22 18:05:29 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 17 | package commands |
| 18 | |
| 19 | import ( |
| 20 | "bytes" |
Scott Baker | 14c8f18 | 2019-05-22 18:05:29 -0700 | [diff] [blame] | 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | func 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 | |
| 54 | func 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" + |
| 67 | " Git commit: b0df1bf6ed1698285eda6a6725c5da0c80aa4aee\n" + |
| 68 | " Built: 2019-05-20T17:04:14Z\n" + |
| 69 | " OS/Arch: linux/x86_64\n" + |
| 70 | "\n" |
| 71 | |
| 72 | got := new(bytes.Buffer) |
| 73 | OutputStream = got |
| 74 | |
| 75 | var options VersionOpts |
| 76 | err := options.Execute([]string{}) |
| 77 | |
| 78 | if err != nil { |
| 79 | t.Errorf("%s: Received error %v", t.Name(), err) |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | if got.String() != expected { |
| 84 | t.Logf("RECEIVED:\n%s\n", got.String()) |
| 85 | t.Logf("EXPECTED:\n%s\n", expected) |
| 86 | t.Errorf("%s: expected and received did not match", t.Name()) |
| 87 | } |
| 88 | } |