Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 495f79c

Browse files
committed
test(GetAnalyzers): add unit tests
1 parent 392830b commit 495f79c

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

differs/differs_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2017 Google, Inc. 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 differs
18+
19+
import (
20+
"reflect"
21+
"testing"
22+
)
23+
24+
func TestGetAnalyzers(t *testing.T) {
25+
26+
tests := []struct {
27+
name string
28+
args []string
29+
want []Analyzer
30+
wantErr bool
31+
}{
32+
{
33+
name: "given only one type",
34+
args: []string{"history"},
35+
want: []Analyzer{HistoryAnalyzer{}},
36+
wantErr: false,
37+
},
38+
{
39+
name: "given two type",
40+
args: []string{"file", "apt"},
41+
want: []Analyzer{FileAnalyzer{}, AptAnalyzer{}},
42+
wantErr: false,
43+
},
44+
{
45+
name: "given non-existent type",
46+
args: []string{"faketype"},
47+
want: nil,
48+
wantErr: true,
49+
},
50+
{
51+
name: "no type given",
52+
args: []string{},
53+
want: nil,
54+
wantErr: true,
55+
},
56+
}
57+
for _, tt := range tests {
58+
t.Run(tt.name, func(t *testing.T) {
59+
got, err := GetAnalyzers(tt.args)
60+
if (err != nil) != tt.wantErr {
61+
t.Errorf("GetAnalyzers() error = %v, wantErr %v", err, tt.wantErr)
62+
return
63+
} else if err != nil && tt.wantErr {
64+
t.Logf("errored out as = %v", err)
65+
}
66+
if !reflect.DeepEqual(got, tt.want) {
67+
t.Errorf("GetAnalyzers() = %#v, want %#v", got, tt.want)
68+
}
69+
})
70+
}
71+
}

0 commit comments

Comments
 (0)