(t *testing.T)
| 150 | } |
| 151 | |
| 152 | func TestKeyValueWatch(t *testing.T) { |
| 153 | expectUpdateF := func(t *testing.T, watcher nats.KeyWatcher) func(key, value string, revision uint64) { |
| 154 | return func(key, value string, revision uint64) { |
| 155 | t.Helper() |
| 156 | select { |
| 157 | case v := <-watcher.Updates(): |
| 158 | if v.Key() != key || string(v.Value()) != value || v.Revision() != revision { |
| 159 | t.Fatalf("Did not get expected: %q %q %d vs %q %q %d", v.Key(), string(v.Value()), v.Revision(), key, value, revision) |
| 160 | } |
| 161 | case <-time.After(time.Second): |
| 162 | t.Fatalf("Did not receive an update like expected") |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | expectDeleteF := func(t *testing.T, watcher nats.KeyWatcher) func(key string, revision uint64) { |
| 167 | return func(key string, revision uint64) { |
| 168 | t.Helper() |
| 169 | select { |
| 170 | case v := <-watcher.Updates(): |
| 171 | if v.Operation() != nats.KeyValueDelete { |
| 172 | t.Fatalf("Expected a delete operation but got %+v", v) |
| 173 | } |
| 174 | if v.Revision() != revision { |
| 175 | t.Fatalf("Did not get expected revision: %d vs %d", revision, v.Revision()) |
| 176 | } |
| 177 | case <-time.After(time.Second): |
| 178 | t.Fatalf("Did not receive an update like expected") |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | expectPurgeF := func(t *testing.T, watcher nats.KeyWatcher) func(key string, revision uint64) { |
| 183 | return func(key string, revision uint64) { |
| 184 | t.Helper() |
| 185 | select { |
| 186 | case v := <-watcher.Updates(): |
| 187 | if v.Operation() != nats.KeyValuePurge { |
| 188 | t.Fatalf("Expected a delete operation but got %+v", v) |
| 189 | } |
| 190 | if v.Revision() != revision { |
| 191 | t.Fatalf("Did not get expected revision: %d vs %d", revision, v.Revision()) |
| 192 | } |
| 193 | case <-time.After(time.Second): |
| 194 | t.Fatalf("Did not receive an update like expected") |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | expectInitDoneF := func(t *testing.T, watcher nats.KeyWatcher) func() { |
| 199 | return func() { |
| 200 | t.Helper() |
| 201 | select { |
| 202 | case v := <-watcher.Updates(): |
| 203 | if v != nil { |
| 204 | t.Fatalf("Did not get expected: %+v", v) |
| 205 | } |
| 206 | case <-time.After(time.Second): |
| 207 | t.Fatalf("Did not receive a init done like expected") |
| 208 | } |
| 209 | } |
nothing calls this directly
no test coverage detected