describe_log_dirs_response_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package sarama
  2. import (
  3. "testing"
  4. )
  5. var (
  6. describeLogDirsResponseEmpty = []byte{
  7. 0, 0, 0, 0, // no throttle time
  8. 0, 0, 0, 0, // no log dirs
  9. }
  10. describeLogDirsResponseTwoPartitions = []byte{
  11. 0, 0, 0, 0, // no throttle time
  12. 0, 0, 0, 1, // One describe log dir (array length)
  13. 0, 0, // No error code
  14. 0, 6, // Character length of path (6 chars)
  15. '/', 'k', 'a', 'f', 'k', 'a',
  16. 0, 0, 0, 1, // One DescribeLogDirsResponseTopic (array length)
  17. 0, 6, // Character length of "random" topic (6 chars)
  18. 'r', 'a', 'n', 'd', 'o', 'm', // Topic name
  19. 0, 0, 0, 2, // Two DescribeLogDirsResponsePartition (array length)
  20. 0, 0, 0, 25, // PartitionID 25
  21. 0, 0, 0, 0, 0, 0, 0, 125, // Log Size
  22. 0, 0, 0, 0, 0, 0, 0, 0, // OffsetLag
  23. 0, // IsTemporary = false
  24. 0, 0, 0, 26, // PartitionID 25
  25. 0, 0, 0, 0, 0, 0, 0, 100, // Log Size
  26. 0, 0, 0, 0, 0, 0, 0, 0, // OffsetLag
  27. 0, // IsTemporary = false
  28. }
  29. )
  30. func TestDescribeLogDirsResponse(t *testing.T) {
  31. // Test empty response
  32. response := &DescribeLogDirsResponse{
  33. LogDirs: []DescribeLogDirsResponseDirMetadata{},
  34. }
  35. testVersionDecodable(t, "empty", response, describeLogDirsResponseEmpty, 0)
  36. if len(response.LogDirs) != 0 {
  37. t.Error("Expected no log dirs")
  38. }
  39. response.LogDirs = []DescribeLogDirsResponseDirMetadata{
  40. {
  41. ErrorCode: 0,
  42. Path: "/kafka",
  43. Topics: []DescribeLogDirsResponseTopic{
  44. {
  45. Topic: "random",
  46. Partitions: []DescribeLogDirsResponsePartition{
  47. {
  48. PartitionID: 25,
  49. Size: 125,
  50. OffsetLag: 0,
  51. IsTemporary: false,
  52. },
  53. {
  54. PartitionID: 26,
  55. Size: 100,
  56. OffsetLag: 0,
  57. IsTemporary: false,
  58. },
  59. },
  60. },
  61. },
  62. },
  63. }
  64. testVersionDecodable(t, "two partitions", response, describeLogDirsResponseTwoPartitions, 0)
  65. if len(response.LogDirs) != 1 {
  66. t.Error("Expected one log dirs")
  67. }
  68. if len(response.LogDirs[0].Topics) != 1 {
  69. t.Error("Expected one topic in log dirs")
  70. }
  71. if len(response.LogDirs[0].Topics[0].Partitions) != 2 {
  72. t.Error("Expected two partitions")
  73. }
  74. }