util_test.go 896 B

1234567891011121314151617181920212223242526272829
  1. package server
  2. import (
  3. "github.com/stretchr/testify/require"
  4. "net/http"
  5. "testing"
  6. )
  7. func TestReadBoolParam(t *testing.T) {
  8. r, _ := http.NewRequest("GET", "https://ntfy.sh/mytopic?up=1&firebase=no", nil)
  9. up := readBoolParam(r, false, "x-up", "up")
  10. firebase := readBoolParam(r, true, "x-firebase", "firebase")
  11. require.Equal(t, true, up)
  12. require.Equal(t, false, firebase)
  13. r, _ = http.NewRequest("GET", "https://ntfy.sh/mytopic", nil)
  14. r.Header.Set("X-Up", "yes")
  15. r.Header.Set("X-Firebase", "0")
  16. up = readBoolParam(r, false, "x-up", "up")
  17. firebase = readBoolParam(r, true, "x-firebase", "firebase")
  18. require.Equal(t, true, up)
  19. require.Equal(t, false, firebase)
  20. r, _ = http.NewRequest("GET", "https://ntfy.sh/mytopic", nil)
  21. up = readBoolParam(r, false, "x-up", "up")
  22. firebase = readBoolParam(r, true, "x-up", "up")
  23. require.Equal(t, false, up)
  24. require.Equal(t, true, firebase)
  25. }