|
| 1 | +package box |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | + "github.com/vmihailenco/msgpack/v5" |
| 8 | +) |
| 9 | + |
| 10 | +func TestInfoRequest(t *testing.T) { |
| 11 | + id := 1 |
| 12 | + cases := []struct { |
| 13 | + Name string |
| 14 | + Struct Info |
| 15 | + Data map[string]interface{} |
| 16 | + }{ |
| 17 | + { |
| 18 | + Name: "Case: base info struct", |
| 19 | + Struct: Info{ |
| 20 | + Version: "2.11.4-0-g8cebbf2cad", |
| 21 | + ID: &id, |
| 22 | + RO: false, |
| 23 | + UUID: "69360e9b-4641-4ec3-ab51-297f46749849", |
| 24 | + PID: 1, |
| 25 | + Status: "running", |
| 26 | + LSN: 8, |
| 27 | + }, |
| 28 | + Data: map[string]interface{}{ |
| 29 | + "version": "2.11.4-0-g8cebbf2cad", |
| 30 | + "id": 1, |
| 31 | + "ro": false, |
| 32 | + "uuid": "69360e9b-4641-4ec3-ab51-297f46749849", |
| 33 | + "pid": 1, |
| 34 | + "status": "running", |
| 35 | + "lsn": 8, |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + Name: "Case: info struct with replication", |
| 40 | + Struct: Info{ |
| 41 | + Version: "2.11.4-0-g8cebbf2cad", |
| 42 | + ID: &id, |
| 43 | + RO: false, |
| 44 | + UUID: "69360e9b-4641-4ec3-ab51-297f46749849", |
| 45 | + PID: 1, |
| 46 | + Status: "running", |
| 47 | + LSN: 8, |
| 48 | + Replication: map[int]Replication{ |
| 49 | + 1: { |
| 50 | + ID: 1, |
| 51 | + UUID: "69360e9b-4641-4ec3-ab51-297f46749849", |
| 52 | + LSN: 8, |
| 53 | + }, |
| 54 | + 2: { |
| 55 | + ID: 2, |
| 56 | + UUID: "75f5f5aa-89f0-4d95-b5a9-96a0eaa0ce36", |
| 57 | + LSN: 0, |
| 58 | + Upstream: Upstream{ |
| 59 | + Status: "follow", |
| 60 | + Idle: 2.4564633660484, |
| 61 | + Peer: "other.tarantool:3301", |
| 62 | + Lag: 0.00011920928955078, |
| 63 | + Message: "'getaddrinfo: Name or service not known: Input/output error'", |
| 64 | + SystemMessage: "Input/output error", |
| 65 | + }, |
| 66 | + Downstream: Downstream{ |
| 67 | + Status: "follow", |
| 68 | + Idle: 2.8306158290943, |
| 69 | + VClock: map[int]uint64{1: 8}, |
| 70 | + Lag: 0, |
| 71 | + Message: "'unexpected EOF when reading from socket'", |
| 72 | + SystemMessage: "Broken pipe", |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + Data: map[string]interface{}{ |
| 78 | + "version": "2.11.4-0-g8cebbf2cad", |
| 79 | + "id": 1, |
| 80 | + "ro": false, |
| 81 | + "uuid": "69360e9b-4641-4ec3-ab51-297f46749849", |
| 82 | + "pid": 1, |
| 83 | + "status": "running", |
| 84 | + "lsn": 8, |
| 85 | + "replication": map[interface{}]interface{}{ |
| 86 | + 1: map[string]interface{}{ |
| 87 | + "id": 1, |
| 88 | + "uuid": "69360e9b-4641-4ec3-ab51-297f46749849", |
| 89 | + "lsn": 8, |
| 90 | + }, |
| 91 | + 2: map[string]interface{}{ |
| 92 | + "id": 2, |
| 93 | + "uuid": "75f5f5aa-89f0-4d95-b5a9-96a0eaa0ce36", |
| 94 | + "lsn": 0, |
| 95 | + "upstream": map[string]interface{}{ |
| 96 | + "status": "follow", |
| 97 | + "idle": 2.4564633660484, |
| 98 | + "peer": "other.tarantool:3301", |
| 99 | + "lag": 0.00011920928955078, |
| 100 | + "message": "'getaddrinfo: Name or service not known: Input/output error'", |
| 101 | + "system_message": "Input/output error", |
| 102 | + }, |
| 103 | + "downstream": map[string]interface{}{ |
| 104 | + "status": "follow", |
| 105 | + "idle": 2.8306158290943, |
| 106 | + "vclock": map[interface{}]interface{}{1: 8}, |
| 107 | + "lag": 0, |
| 108 | + "message": "'unexpected EOF when reading from socket'", |
| 109 | + "system_message": "Broken pipe", |
| 110 | + }, |
| 111 | + }, |
| 112 | + }, |
| 113 | + }, |
| 114 | + }, |
| 115 | + } |
| 116 | + for _, tc := range cases { |
| 117 | + data, err := msgpack.Marshal(tc.Data) |
| 118 | + require.NoError(t, err, tc.Name) |
| 119 | + |
| 120 | + var result Info |
| 121 | + err = msgpack.Unmarshal(data, &result) |
| 122 | + require.NoError(t, err, tc.Name) |
| 123 | + |
| 124 | + require.Equal(t, tc.Struct, result) |
| 125 | + } |
| 126 | +} |
0 commit comments