5
5
"encoding/base64"
6
6
"encoding/json"
7
7
"errors"
8
- "io/ioutil"
9
8
"os"
10
9
"os/exec"
11
10
"path/filepath"
@@ -49,7 +48,7 @@ func TestGetCollectors(t *testing.T) {
49
48
initCollectors := []collector.Collector {}
50
49
initCollectors = append (initCollectors , fileCollector )
51
50
52
- collectors := getCollectors (initCollectors )
51
+ collectors , _ := getCollectors (initCollectors )
53
52
54
53
if collectors != nil && len (collectors ) != 1 {
55
54
t .Errorf ("Did not get file collector correctly with error: %s" , err )
@@ -102,7 +101,7 @@ func TestStoreCollectorError(t *testing.T) {
102
101
}
103
102
104
103
func TestMainExitCodes (t * testing.T ) {
105
- tmpDir , err := ioutil . TempDir (os .TempDir (), "kubent-tests-" )
104
+ tmpDir , err := os . MkdirTemp (os .TempDir (), "kubent-tests-" )
106
105
if err != nil {
107
106
t .Fatalf ("failed to create temp dir for testing: %v" , err )
108
107
}
@@ -128,6 +127,7 @@ func TestMainExitCodes(t *testing.T) {
128
127
{"version long flag set" , []string {"--version" }, 0 , "" , "" , false },
129
128
{"empty text output" , []string {clusterFlagDisabled , helm3FlagDisabled }, 0 , "" , "" , false },
130
129
{"empty json output" , []string {"-o=json" , clusterFlagDisabled , helm3FlagDisabled }, 0 , "[]\n " , "" , false },
130
+ {"Failed to initialize collectors" , []string {"-o=json" , "-l=disabled" }, 200 , "[]\n " , "" , true },
131
131
{"json-file" , []string {"-o=json" , clusterFlagDisabled , helm3FlagDisabled , "-f=" + filepath .Join (FIXTURES_DIR , "deployment-v1beta1.yaml" )}, 0 , "" , filepath .Join (tmpDir , "json-file.out" ), false },
132
132
{"text-file" , []string {"-o=text" , clusterFlagDisabled , helm3FlagDisabled , "-f=" + filepath .Join (FIXTURES_DIR , "deployment-v1beta1.yaml" )}, 0 , "" , filepath .Join (tmpDir , "text-file.out" ), false },
133
133
{"json-stdout" , []string {"-o=json" , clusterFlagDisabled , helm3FlagDisabled , "-f=" + filepath .Join (FIXTURES_DIR , "deployment-v1beta1.yaml" )}, 0 , string (expectedJsonOutput ), "-" , false },
@@ -268,8 +268,8 @@ func decodeBase64(dst *[]string, encoded string) error {
268
268
269
269
func Test_outputResults (t * testing.T ) {
270
270
testVersion , _ := judge .NewVersion ("4.5.6" )
271
- testResults := []judge.Result {{"name" , "ns" , "kind" ,
272
- "1.2.3" , "rs" , "rep" , testVersion }}
271
+ testResults := []judge.Result {{Name : "name" , Namespace : "ns" , Kind : "kind" ,
272
+ ApiVersion : "1.2.3" , RuleSet : "rs" , ReplaceWith : "rep" , Since : testVersion }}
273
273
274
274
type args struct {
275
275
results []judge.Result
0 commit comments