(t *testing.T)
| 1200 | } |
| 1201 | |
| 1202 | func TestKeyValueCrossAccounts(t *testing.T) { |
| 1203 | conf := createConfFile(t, []byte(` |
| 1204 | listen: 127.0.0.1:-1 |
| 1205 | jetstream: enabled |
| 1206 | accounts: { |
| 1207 | A: { |
| 1208 | users: [ {user: a, password: a} ] |
| 1209 | jetstream: enabled |
| 1210 | exports: [ |
| 1211 | {service: '$JS.API.>' } |
| 1212 | {service: '$KV.>'} |
| 1213 | {stream: 'accI.>'} |
| 1214 | ] |
| 1215 | }, |
| 1216 | I: { |
| 1217 | users: [ {user: i, password: i} ] |
| 1218 | imports: [ |
| 1219 | {service: {account: A, subject: '$JS.API.>'}, to: 'fromA.>' } |
| 1220 | {service: {account: A, subject: '$KV.>'}, to: 'fromA.$KV.>' } |
| 1221 | {stream: {subject: 'accI.>', account: A}} |
| 1222 | ] |
| 1223 | } |
| 1224 | }`)) |
| 1225 | defer os.Remove(conf) |
| 1226 | s, _ := RunServerWithConfig(conf) |
| 1227 | defer shutdownJSServerAndRemoveStorage(t, s) |
| 1228 | |
| 1229 | watchNext := func(w jetstream.KeyWatcher) jetstream.KeyValueEntry { |
| 1230 | t.Helper() |
| 1231 | select { |
| 1232 | case e := <-w.Updates(): |
| 1233 | return e |
| 1234 | case <-time.After(time.Second): |
| 1235 | t.Fatal("Fail to get the next update") |
| 1236 | } |
| 1237 | return nil |
| 1238 | } |
| 1239 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1240 | defer cancel() |
| 1241 | |
| 1242 | nc1, js1 := jsClient(t, s, nats.UserInfo("a", "a")) |
| 1243 | defer nc1.Close() |
| 1244 | |
| 1245 | kv1, err := js1.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "Map", History: 10}) |
| 1246 | if err != nil { |
| 1247 | t.Fatalf("Error creating kv store: %v", err) |
| 1248 | } |
| 1249 | |
| 1250 | w1, err := kv1.Watch(ctx, "map") |
| 1251 | if err != nil { |
| 1252 | t.Fatalf("Error creating watcher: %v", err) |
| 1253 | } |
| 1254 | if e := watchNext(w1); e != nil { |
| 1255 | t.Fatalf("Expected nil entry, got %+v", e) |
| 1256 | } |
| 1257 | |
| 1258 | nc2, err := nats.Connect(s.ClientURL(), nats.UserInfo("i", "i"), nats.CustomInboxPrefix("accI")) |
| 1259 | if err != nil { |
nothing calls this directly
no test coverage detected