github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/internal/httpx/content_type_test.go (about)

     1  package httpx
     2  
     3  import (
     4  	"net/http/httptest"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func Test_ContentType(t *testing.T) {
    11  	r := require.New(t)
    12  
    13  	table := []struct {
    14  		Header   string
    15  		Value    string
    16  		Expected string
    17  	}{
    18  		{"content-type", "a", "a"},
    19  		{"Content-Type", "c,d", "c"},
    20  		{"Content-Type", "e;f", "e"},
    21  		{"Content-Type", "", ""},
    22  		{"Accept", "", ""},
    23  		{"Accept", "*/*", ""},
    24  		{"Accept", "*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript", "text/javascript"},
    25  		{"accept", "text/javascript,application/javascript,application/ecmascript,application/x-ecmascript", "text/javascript"},
    26  	}
    27  
    28  	for _, tt := range table {
    29  		req := httptest.NewRequest("GET", "/", nil)
    30  		req.Header.Set(tt.Header, tt.Value)
    31  		r.Equal(tt.Expected, ContentType(req))
    32  	}
    33  }