httputils_test.go 899 B

12345678910111213141516171819202122232425262728
  1. package httputils // import "github.com/docker/docker/api/server/httputils"
  2. import "testing"
  3. // matchesContentType
  4. func TestJsonContentType(t *testing.T) {
  5. err := matchesContentType("application/json", "application/json")
  6. if err != nil {
  7. t.Error(err)
  8. }
  9. err = matchesContentType("application/json; charset=utf-8", "application/json")
  10. if err != nil {
  11. t.Error(err)
  12. }
  13. expected := "unsupported Content-Type header (dockerapplication/json): must be 'application/json'"
  14. err = matchesContentType("dockerapplication/json", "application/json")
  15. if err == nil || err.Error() != expected {
  16. t.Errorf(`expected "%s", got "%v"`, expected, err)
  17. }
  18. expected = "malformed Content-Type header (foo;;;bar): mime: invalid media parameter"
  19. err = matchesContentType("foo;;;bar", "application/json")
  20. if err == nil || err.Error() != expected {
  21. t.Errorf(`expected "%s", got "%v"`, expected, err)
  22. }
  23. }