httputil_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package httputil
  2. import (
  3. "net/http"
  4. "net/url"
  5. "testing"
  6. "github.com/google/go-cmp/cmp"
  7. )
  8. func TestInvalidKeys(t *testing.T) {
  9. vals := url.Values{}
  10. vals.Set("window", "7d")
  11. vals.Set("aggregate", "namespace")
  12. vals.Set("filterClsuters", "cluster-two") // Intentional typo
  13. qp := NewQueryParams(vals)
  14. result := qp.InvalidKeys([]string{"window", "aggregate", "filterClusters", "filterNamespaces"})
  15. expected := []string{"filterClsuters"}
  16. if diff := cmp.Diff(result, expected); len(diff) > 0 {
  17. t.Errorf("Expected: %+v. Got: %+v", expected, result)
  18. }
  19. }
  20. func TestHeaderString(t *testing.T) {
  21. h := make(http.Header)
  22. h.Add("foo", "abc")
  23. h.Add("foo", "123")
  24. h.Add("bar", "foo")
  25. h.Add("Content-Type", "application/octet-stream")
  26. s := HeaderString(h)
  27. if len(s) == 0 {
  28. t.Errorf("Header String failed to produce a valid output")
  29. return
  30. }
  31. t.Logf("Result: %s\n", s)
  32. }
  33. func TestEmptyHeader(t *testing.T) {
  34. h := make(http.Header)
  35. s := HeaderString(h)
  36. if len(s) == 0 {
  37. t.Errorf("Header String failed to produce a valid output")
  38. return
  39. }
  40. t.Logf("Result: %s\n", s)
  41. }
  42. func TestNilHeader(t *testing.T) {
  43. var h http.Header
  44. s := HeaderString(h)
  45. if len(s) == 0 {
  46. t.Errorf("Header String failed to produce a valid output")
  47. return
  48. }
  49. t.Logf("Result: %s\n", s)
  50. }