759ab114d6ad3115cf7319881c92b0e2259c0f98
[ric-plt/sdlgo.git] / internal / cli / get_test.go
1 /*
2    Copyright (c) 2021 AT&T Intellectual Property.
3    Copyright (c) 2018-2021 Nokia.
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
18 /*
19  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20  * platform project (RICP).
21  */
22
23 package cli_test
24
25 import (
26         "bytes"
27         "errors"
28         "gerrit.o-ran-sc.org/r/ric-plt/sdlgo/internal/cli"
29         "github.com/stretchr/testify/assert"
30         "testing"
31 )
32
33 func TestGetCmdShowHelp(t *testing.T) {
34         var expOkErr error
35         expHelp := "Display one or many resources.\n\nPrints important information about the specified resources."
36         expExamples := "Examples:\n  # List keys in the given namespace."
37         expNokErr := errors.New("unknown flag: --ff")
38         tests := []struct {
39                 args   []string
40                 expErr error
41                 expOut string
42         }{
43                 {args: []string{"-h"}, expErr: expOkErr, expOut: expHelp},
44                 {args: []string{"--help"}, expErr: expOkErr, expOut: expHelp},
45                 {args: []string{}, expErr: expOkErr, expOut: expHelp},
46                 {args: []string{"--ff"}, expErr: expNokErr, expOut: expExamples},
47         }
48
49         for _, test := range tests {
50                 buf := new(bytes.Buffer)
51                 cmd := cli.NewGetCmdForTest()
52                 cmd.SetOut(buf)
53                 cmd.SetErr(buf)
54                 cmd.SetArgs(test.args)
55                 err := cmd.Execute()
56                 result := buf.String()
57
58                 assert.Equal(t, test.expErr, err)
59                 assert.Contains(t, result, test.expOut)
60         }
61 }