nsq_to_http_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // This is an NSQ client that reads the specified topic/channel
  2. // and performs HTTP requests (GET/POST) to the specified endpoints
  3. package main
  4. import (
  5. "reflect"
  6. "testing"
  7. )
  8. func TestParseCustomHeaders(t *testing.T) {
  9. type args struct {
  10. strs []string
  11. }
  12. tests := []struct {
  13. name string
  14. args args
  15. want map[string]string
  16. wantErr bool
  17. }{
  18. {
  19. "Valid Custom Headers",
  20. args{[]string{"header1: value1", "header2:value2", "header3:value3", "header4:value4"}},
  21. map[string]string{"header1": "value1", "header2": "value2", "header3": "value3", "header4": "value4"},
  22. false,
  23. },
  24. {
  25. "Invalid Custom Headers where key is present but no value",
  26. args{[]string{"header1:", "header2:value2", "header3: value3", "header4:value4"}},
  27. nil,
  28. true,
  29. },
  30. {
  31. "Invalid Custom Headers where key is not present but value is present",
  32. args{[]string{"header1: value1", ": value2", "header3:value3", "header4:value4"}},
  33. nil,
  34. true,
  35. },
  36. {
  37. "Invalid Custom Headers where key and value are not present but ':' is specified",
  38. args{[]string{"header1:value1", "header2:value2", ":", "header4:value4"}},
  39. nil,
  40. true,
  41. },
  42. }
  43. for _, tt := range tests {
  44. t.Run(tt.name, func(t *testing.T) {
  45. got, err := parseCustomHeaders(tt.args.strs)
  46. if (err != nil) != tt.wantErr {
  47. t.Errorf("parseCustomHeaders() error = %v, wantErr %v", err, tt.wantErr)
  48. return
  49. }
  50. if !reflect.DeepEqual(got, tt.want) {
  51. t.Errorf("parseCustomHeaders() = %v, want %v", got, tt.want)
  52. }
  53. })
  54. }
  55. }