-
Notifications
You must be signed in to change notification settings - Fork 155
add interfaces flag with unit test #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
900159e
5a7af37
6cc01b1
2553835
ec91f0c
df7752f
89fa9e9
db487ea
ca7477a
6c12923
e1e3ec9
a6a5b06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,10 @@ package main | |
| import ( | ||
| "go/parser" | ||
| "go/token" | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "go.uber.org/mock/mockgen/model" | ||
| ) | ||
|
|
||
| func TestFileParser_ParseFile(t *testing.T) { | ||
|
|
@@ -143,3 +146,127 @@ func TestParseArrayWithConstLength(t *testing.T) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| func Test_filterInterfaces(t *testing.T) { | ||
| type args struct { | ||
| all []*model.Interface | ||
| requested []string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| want []*model.Interface | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "no filter (returns all interfaces)", | ||
| args: args{ | ||
| all: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| { | ||
| Name: "Bar", | ||
| }, | ||
| }, | ||
| requested: []string{}, | ||
| }, | ||
| want: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| { | ||
| Name: "Bar", | ||
| }, | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "filter by Foo", | ||
| args: args{ | ||
| all: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| { | ||
| Name: "Bar", | ||
| }, | ||
| }, | ||
| requested: []string{"Foo"}, | ||
| }, | ||
| want: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "filter by Foo and Bar", | ||
| args: args{ | ||
| all: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| { | ||
| Name: "Bar", | ||
| }, | ||
| }, | ||
| requested: []string{"Foo", "Bar"}, | ||
| }, | ||
| want: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| { | ||
| Name: "Bar", | ||
| }, | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "incorrect filter by Foo and Baz", | ||
| args: args{ | ||
| all: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| { | ||
| Name: "Bar", | ||
| }, | ||
| }, | ||
| requested: []string{"Foo", "Baz"}, | ||
| }, | ||
| want: nil, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "missing interface (Baz not found)", | ||
|
||
| args: args{ | ||
| all: []*model.Interface{ | ||
| { | ||
| Name: "Foo", | ||
| }, | ||
| { | ||
| Name: "Bar", | ||
| }, | ||
| }, | ||
| requested: []string{"Baz"}, | ||
| }, | ||
| want: nil, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := filterInterfaces(tt.args.all, tt.args.requested) | ||
| if (err != nil) != tt.wantErr { | ||
|
||
| t.Errorf("filterInterfaces() error = %v, wantErr %v", err, tt.wantErr) | ||
| return | ||
| } | ||
| if !reflect.DeepEqual(got, tt.want) { | ||
| t.Errorf("filterInterfaces() got = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this is still doing the thing @JacobOaks's comment advised against: