-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improves coverage of media type detector.
- Loading branch information
1 parent
950f653
commit e15f173
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package proxy | ||
|
||
import "testing" | ||
|
||
func Test_isTextContentType(t *testing.T) { | ||
type args struct { | ||
contentType string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "empty content type", | ||
args: args{contentType: ""}, | ||
want: false, | ||
}, | ||
{ | ||
name: "invalid content type", | ||
args: args{contentType: "invalid/contenttype"}, | ||
want: false, | ||
}, | ||
{ | ||
name: "text content type", | ||
args: args{contentType: "text/plain"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "json content type", | ||
args: args{contentType: "application/json"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "xml content type", | ||
args: args{contentType: "application/xml"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "javascript content type", | ||
args: args{contentType: "application/javascript"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "form-urlencoded content type", | ||
args: args{contentType: "application/x-www-form-urlencoded"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "non-text content type", | ||
args: args{contentType: "application/octet-stream"}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := isTextContentType(tt.args.contentType); got != tt.want { | ||
t.Errorf("isTextContentType() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |