Debian Codegraph @

cmd/archivistactl/cmd/retrieve_test.go

raw
1 // Copyright 2023 The Archivista Contributors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package cmd
16
17 import (
18 "bytes"
19 "testing"
20
21 "github.com/stretchr/testify/suite"
22 )
23
24 // Test Suite: UT Retrieve
25 type UTRetrieveSuite struct {
26 suite.Suite
27 }
28
29 func TestUTRetrieveSuite(t *testing.T) {
30 suite.Run(t, new(UTRetrieveSuite))
31 }
32
33 func (ut *UTRetrieveSuite) Test_MissingSubCommand() {
34 output := bytes.NewBufferString("")
35 rootCmd.SetOut(output)
36 rootCmd.SetErr(output)
37 rootCmd.SetArgs([]string{"retrieve"})
38 err := rootCmd.Execute()
39 if err != nil {
40 ut.FailNow("Expected: error")
41 }
42 ut.Contains(output.String(), "archivistactl retrieve")
43 }
44
45 func (ut *UTRetrieveSuite) Test_RetrieveEnvelopeMissingArg() {
46 output := bytes.NewBufferString("")
47 rootCmd.SetOut(output)
48 rootCmd.SetErr(output)
49 rootCmd.SetArgs([]string{"retrieve", "envelope"})
50 err := rootCmd.Execute()
51 if err != nil {
52 ut.ErrorContains(err, "accepts 1 arg(s), received 0")
53 } else {
54 ut.FailNow("Expected: error")
55 }
56 }
57
58 func (ut *UTRetrieveSuite) Test_RetrieveEnvelope_NoDB() {
59 output := bytes.NewBufferString("")
60 rootCmd.SetOut(output)
61 rootCmd.SetErr(output)
62 rootCmd.SetArgs([]string{"retrieve", "envelope", "test"})
63 err := rootCmd.Execute()
64 if err != nil {
65 ut.ErrorContains(err, "connection re")
66 } else {
67 ut.FailNow("Expected: error")
68 }
69 }
70
71 func (ut *UTRetrieveSuite) Test_RetrieveSubjectsMissingArg() {
72 output := bytes.NewBufferString("")
73 rootCmd.SetOut(output)
74 rootCmd.SetErr(output)
75 rootCmd.SetArgs([]string{"retrieve", "subjects"})
76 err := rootCmd.Execute()
77 if err != nil {
78 ut.ErrorContains(err, "accepts 1 arg(s), received 0")
79 } else {
80 ut.FailNow("Expected: error")
81 }
82 }
83
84 func (ut *UTRetrieveSuite) Test_RetrieveSubjectsNoDB() {
85 output := bytes.NewBufferString("")
86 rootCmd.SetOut(output)
87 rootCmd.SetErr(output)
88 rootCmd.SetArgs([]string{"retrieve", "subjects", "test"})
89 err := rootCmd.Execute()
90 if err != nil {
91 ut.ErrorContains(err, "connection re")
92 } else {
93 ut.FailNow("Expected: error")
94 }
95 }