confirm_test.go 668 B

123456789101112131415161718192021222324252627282930
  1. package web
  2. import (
  3. "net/url"
  4. "testing"
  5. )
  6. func Test__getOp(t *testing.T) {
  7. empty := []string{""}
  8. for _, test := range [...]struct {
  9. name string
  10. input url.Values
  11. expected QueueOp
  12. }{
  13. {"delete", url.Values{"delete": empty}, OpDelete},
  14. {"redrive", url.Values{"redrive": empty}, OpRedrive},
  15. {"none", url.Values{"whatever": empty}, OpInvalid},
  16. {"both", url.Values{"delete": nil, "redrive": nil}, OpInvalid},
  17. } {
  18. t.Run(test.name, func(t *testing.T) {
  19. var u = url.URL{
  20. RawQuery: test.input.Encode(),
  21. }
  22. actual := getOp(&u)
  23. if actual != test.expected {
  24. t.Errorf("got %s but expected %s", actual, test.expected)
  25. }
  26. })
  27. }
  28. }