TestMovedAndAskErrorsWithHookWrapping tests MOVED and ASK errors with wrapping
(t *testing.T)
| 96 | |
| 97 | // TestMovedAndAskErrorsWithHookWrapping tests MOVED and ASK errors with wrapping |
| 98 | func TestMovedAndAskErrorsWithHookWrapping(t *testing.T) { |
| 99 | tests := []struct { |
| 100 | name string |
| 101 | errorMsg string |
| 102 | expectedAddr string |
| 103 | isMoved bool |
| 104 | }{ |
| 105 | { |
| 106 | name: "MOVED error", |
| 107 | errorMsg: "MOVED 3999 127.0.0.1:6381", |
| 108 | expectedAddr: "127.0.0.1:6381", |
| 109 | isMoved: true, |
| 110 | }, |
| 111 | { |
| 112 | name: "ASK error", |
| 113 | errorMsg: "ASK 3999 192.168.1.100:6380", |
| 114 | expectedAddr: "192.168.1.100:6380", |
| 115 | isMoved: false, |
| 116 | }, |
| 117 | } |
| 118 | |
| 119 | for _, tt := range tests { |
| 120 | t.Run(tt.name, func(t *testing.T) { |
| 121 | // Create the error |
| 122 | parsedErr := proto.ParseErrorReply([]byte("-" + tt.errorMsg)) |
| 123 | |
| 124 | // Wrap it in hooks |
| 125 | wrappedErr := fmt.Errorf("hook wrapper: %w", parsedErr) |
| 126 | doubleWrappedErr := fmt.Errorf("another hook: %w", wrappedErr) |
| 127 | |
| 128 | // Test address extraction from wrapped error |
| 129 | if tt.isMoved { |
| 130 | addr, ok := redis.IsMovedError(doubleWrappedErr) |
| 131 | if !ok { |
| 132 | t.Errorf("IsMovedError failed to detect wrapped MOVED error") |
| 133 | } |
| 134 | if addr != tt.expectedAddr { |
| 135 | t.Errorf("Address mismatch: got %q, want %q", addr, tt.expectedAddr) |
| 136 | } |
| 137 | } else { |
| 138 | addr, ok := redis.IsAskError(doubleWrappedErr) |
| 139 | if !ok { |
| 140 | t.Errorf("IsAskError failed to detect wrapped ASK error") |
| 141 | } |
| 142 | if addr != tt.expectedAddr { |
| 143 | t.Errorf("Address mismatch: got %q, want %q", addr, tt.expectedAddr) |
| 144 | } |
| 145 | } |
| 146 | }) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // TestBackwardCompatibilityWithStringChecks verifies that old string-based |
| 151 | // error checking still works for backward compatibility |
nothing calls this directly
no test coverage detected