TestSearchCommandsRESP2AndRESP3Equivalence tests that search commands return equivalent results for both RESP2 and RESP3 protocols.
(t *testing.T)
| 10 | // TestSearchCommandsRESP2AndRESP3Equivalence tests that search commands |
| 11 | // return equivalent results for both RESP2 and RESP3 protocols. |
| 12 | func TestSearchCommandsRESP2AndRESP3Equivalence(t *testing.T) { |
| 13 | ctx := context.Background() |
| 14 | |
| 15 | // RESP2 client |
| 16 | client2 := redis.NewClient(&redis.Options{ |
| 17 | Addr: "localhost:6379", |
| 18 | Protocol: 2, |
| 19 | }) |
| 20 | defer client2.Close() |
| 21 | |
| 22 | // RESP3 client |
| 23 | client3 := redis.NewClient(&redis.Options{ |
| 24 | Addr: "localhost:6379", |
| 25 | Protocol: 3, |
| 26 | }) |
| 27 | defer client3.Close() |
| 28 | |
| 29 | // Check connection |
| 30 | if err := client2.Ping(ctx).Err(); err != nil { |
| 31 | t.Skipf("Redis not available: %v", err) |
| 32 | } |
| 33 | |
| 34 | // Clean up before test |
| 35 | client2.FTDropIndex(ctx, "test-idx") |
| 36 | client2.Del(ctx, "doc1", "doc2", "doc3") |
| 37 | |
| 38 | t.Run("FTInfo", func(t *testing.T) { |
| 39 | // Create index |
| 40 | _, err := client2.FTCreate(ctx, "test-idx", |
| 41 | &redis.FTCreateOptions{}, |
| 42 | &redis.FieldSchema{FieldName: "title", FieldType: redis.SearchFieldTypeText, Sortable: true}, |
| 43 | &redis.FieldSchema{FieldName: "score", FieldType: redis.SearchFieldTypeNumeric, Sortable: true}, |
| 44 | ).Result() |
| 45 | if err != nil { |
| 46 | t.Fatalf("FTCreate failed: %v", err) |
| 47 | } |
| 48 | defer client2.FTDropIndex(ctx, "test-idx") |
| 49 | |
| 50 | // Add some documents |
| 51 | client2.HSet(ctx, "doc1", "title", "hello world", "score", 100) |
| 52 | client2.HSet(ctx, "doc2", "title", "foo bar", "score", 200) |
| 53 | |
| 54 | // Wait for indexing |
| 55 | waitForIndexing(t, client2, "test-idx", 2) |
| 56 | |
| 57 | // Get FTInfo from both protocols |
| 58 | info2, err := client2.FTInfo(ctx, "test-idx").Result() |
| 59 | if err != nil { |
| 60 | t.Fatalf("FTInfo RESP2 failed: %v", err) |
| 61 | } |
| 62 | |
| 63 | info3, err := client3.FTInfo(ctx, "test-idx").Result() |
| 64 | if err != nil { |
| 65 | t.Fatalf("FTInfo RESP3 failed: %v", err) |
| 66 | } |
| 67 | |
| 68 | // Compare key fields |
| 69 | if info2.IndexName != info3.IndexName { |
nothing calls this directly
no test coverage detected