Skip to content

Commit

Permalink
test: improves coverage of media type detector.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Nov 20, 2024
1 parent 950f653 commit e15f173
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions proxy/content_test.go
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)
}
})
}
}

0 comments on commit e15f173

Please sign in to comment.