alter_configs_request_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package sarama
  2. import "testing"
  3. var (
  4. emptyAlterConfigsRequest = []byte{
  5. 0, 0, 0, 0, // 0 configs
  6. 0, // don't Validate
  7. }
  8. singleAlterConfigsRequest = []byte{
  9. 0, 0, 0, 1, // 1 config
  10. 2, // a topic
  11. 0, 3, 'f', 'o', 'o', // topic name: foo
  12. 0, 0, 0, 1, //1 config name
  13. 0, 10, // 10 chars
  14. 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  15. 0, 4,
  16. '1', '0', '0', '0',
  17. 0, // don't validate
  18. }
  19. doubleAlterConfigsRequest = []byte{
  20. 0, 0, 0, 2, // 2 config
  21. 2, // a topic
  22. 0, 3, 'f', 'o', 'o', // topic name: foo
  23. 0, 0, 0, 1, //1 config name
  24. 0, 10, // 10 chars
  25. 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  26. 0, 4,
  27. '1', '0', '0', '0',
  28. 2, // a topic
  29. 0, 3, 'b', 'a', 'r', // topic name: foo
  30. 0, 0, 0, 1, //2 config
  31. 0, 12, // 12 chars
  32. 'r', 'e', 't', 'e', 'n', 't', 'i', 'o', 'n', '.', 'm', 's',
  33. 0, 4,
  34. '1', '0', '0', '0',
  35. 0, // don't validate
  36. }
  37. )
  38. func TestAlterConfigsRequest(t *testing.T) {
  39. var request *AlterConfigsRequest
  40. request = &AlterConfigsRequest{
  41. Resources: []*AlterConfigsResource{},
  42. }
  43. testRequest(t, "no requests", request, emptyAlterConfigsRequest)
  44. configValue := "1000"
  45. request = &AlterConfigsRequest{
  46. Resources: []*AlterConfigsResource{
  47. {
  48. Type: TopicResource,
  49. Name: "foo",
  50. ConfigEntries: map[string]*string{
  51. "segment.ms": &configValue,
  52. },
  53. },
  54. },
  55. }
  56. testRequest(t, "one config", request, singleAlterConfigsRequest)
  57. request = &AlterConfigsRequest{
  58. Resources: []*AlterConfigsResource{
  59. {
  60. Type: TopicResource,
  61. Name: "foo",
  62. ConfigEntries: map[string]*string{
  63. "segment.ms": &configValue,
  64. },
  65. },
  66. {
  67. Type: TopicResource,
  68. Name: "bar",
  69. ConfigEntries: map[string]*string{
  70. "retention.ms": &configValue,
  71. },
  72. },
  73. },
  74. }
  75. testRequest(t, "two configs", request, doubleAlterConfigsRequest)
  76. }