github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/httpx/content_type_test.go (about)

     1  package httpx
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestHasContentType(t *testing.T) {
    11  	assert.True(t, HasContentType(&http.Request{Header: map[string][]string{}}, "application/octet-stream"))
    12  	assert.False(t, HasContentType(&http.Request{Header: map[string][]string{}}, "not-application/octet-stream"))
    13  	assert.True(t, HasContentType(&http.Request{Header: map[string][]string{"Content-Type": {"application/octet-stream"}}}, "application/octet-stream"))
    14  	assert.True(t, HasContentType(&http.Request{Header: map[string][]string{"Content-Type": {"application/octet-stream, not-application/application"}}}, "not-application/application"))
    15  	assert.True(t, HasContentType(&http.Request{Header: map[string][]string{"Content-Type": {"application/octet-stream,not-application/application"}}}, "not-application/application"))
    16  	assert.False(t, HasContentType(&http.Request{Header: map[string][]string{"Content-Type": {"application/octet-stream, application/not-application"}}}, "not-application/not-octet-stream"))
    17  	assert.False(t, HasContentType(&http.Request{Header: map[string][]string{"Content-Type": {"a"}}}, "not-application/not-octet-stream"))
    18  }