|
| 1 | +/* |
| 2 | + Copyright Digital Asset Holdings, LLC 2016 All Rights Reserved. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package clilogging |
| 18 | + |
| 19 | +import "testing" |
| 20 | + |
| 21 | +// TestGetLevelEmptyParams tests the parameter checking for getlevel, which |
| 22 | +// should return an error when no parameters are provided |
| 23 | +func TestGetLevelEmptyParams(t *testing.T) { |
| 24 | + var args []string |
| 25 | + |
| 26 | + err := checkLoggingCmdParams(getLevelCmd(), args) |
| 27 | + |
| 28 | + if err == nil { |
| 29 | + t.FailNow() |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +// TestGetLevel tests the parameter checking for getlevel, which should |
| 34 | +// should return a nil error when one (or more) parameters are provided |
| 35 | +func TestGetLevel(t *testing.T) { |
| 36 | + args := make([]string, 1) |
| 37 | + args[0] = "peer" |
| 38 | + |
| 39 | + err := checkLoggingCmdParams(getLevelCmd(), args) |
| 40 | + |
| 41 | + if err != nil { |
| 42 | + t.FailNow() |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +// TestSetLevelEmptyParams tests the parameter checking for setlevel, which |
| 47 | +// should return an error when no parameters are provided |
| 48 | +func TestSetLevelEmptyParams(t *testing.T) { |
| 49 | + var args []string |
| 50 | + |
| 51 | + err := checkLoggingCmdParams(setLevelCmd(), args) |
| 52 | + |
| 53 | + if err == nil { |
| 54 | + t.FailNow() |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// TestSetLevelEmptyParams tests the parameter checking for setlevel, which |
| 59 | +// should return an error when only one parameter is provided |
| 60 | +func TestSetLevelOneParam(t *testing.T) { |
| 61 | + args := make([]string, 1) |
| 62 | + args[0] = "peer" |
| 63 | + |
| 64 | + err := checkLoggingCmdParams(setLevelCmd(), args) |
| 65 | + |
| 66 | + if err == nil { |
| 67 | + t.FailNow() |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +// TestSetLevelEmptyParams tests the parameter checking for setlevel, which |
| 72 | +// should return an error when an invalid log level is provided |
| 73 | +func TestSetLevelInvalid(t *testing.T) { |
| 74 | + args := make([]string, 2) |
| 75 | + args[0] = "peer" |
| 76 | + args[1] = "invalidlevel" |
| 77 | + |
| 78 | + err := checkLoggingCmdParams(setLevelCmd(), args) |
| 79 | + |
| 80 | + if err == nil { |
| 81 | + t.FailNow() |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +// TestSetLevelEmptyParams tests the parameter checking for setlevel, which |
| 86 | +// should return a nil error when two parameters, the second of which is a |
| 87 | +// valid log level, are provided |
| 88 | +func TestSetLevel(t *testing.T) { |
| 89 | + args := make([]string, 2) |
| 90 | + args[0] = "peer" |
| 91 | + args[1] = "debug" |
| 92 | + |
| 93 | + err := checkLoggingCmdParams(setLevelCmd(), args) |
| 94 | + |
| 95 | + if err != nil { |
| 96 | + t.FailNow() |
| 97 | + } |
| 98 | +} |
0 commit comments