(t *testing.T)
| 986 | } |
| 987 | |
| 988 | func TestKeyValueCrossAccounts(t *testing.T) { |
| 989 | conf := createConfFile(t, []byte(` |
| 990 | jetstream: enabled |
| 991 | accounts: { |
| 992 | A: { |
| 993 | users: [ {user: a, password: a} ] |
| 994 | jetstream: enabled |
| 995 | exports: [ |
| 996 | {service: '$JS.API.>' } |
| 997 | {service: '$KV.>'} |
| 998 | {stream: 'accI.>'} |
| 999 | ] |
| 1000 | }, |
| 1001 | I: { |
| 1002 | users: [ {user: i, password: i} ] |
| 1003 | imports: [ |
| 1004 | {service: {account: A, subject: '$JS.API.>'}, to: 'fromA.>' } |
| 1005 | {service: {account: A, subject: '$KV.>'}, to: 'fromA.$KV.>' } |
| 1006 | {stream: {subject: 'accI.>', account: A}} |
| 1007 | ] |
| 1008 | } |
| 1009 | }`)) |
| 1010 | defer os.Remove(conf) |
| 1011 | s, _ := RunServerWithConfig(conf) |
| 1012 | defer shutdownJSServerAndRemoveStorage(t, s) |
| 1013 | |
| 1014 | watchNext := func(w nats.KeyWatcher) nats.KeyValueEntry { |
| 1015 | t.Helper() |
| 1016 | select { |
| 1017 | case e := <-w.Updates(): |
| 1018 | return e |
| 1019 | case <-time.After(time.Second): |
| 1020 | t.Fatal("Fail to get the next update") |
| 1021 | } |
| 1022 | return nil |
| 1023 | } |
| 1024 | |
| 1025 | nc1, js1 := jsClient(t, s, nats.UserInfo("a", "a")) |
| 1026 | defer nc1.Close() |
| 1027 | |
| 1028 | kv1, err := js1.CreateKeyValue(&nats.KeyValueConfig{Bucket: "Map", History: 10}) |
| 1029 | if err != nil { |
| 1030 | t.Fatalf("Error creating kv store: %v", err) |
| 1031 | } |
| 1032 | |
| 1033 | w1, err := kv1.Watch("map") |
| 1034 | if err != nil { |
| 1035 | t.Fatalf("Error creating watcher: %v", err) |
| 1036 | } |
| 1037 | if e := watchNext(w1); e != nil { |
| 1038 | t.Fatalf("Expected nil entry, got %+v", e) |
| 1039 | } |
| 1040 | |
| 1041 | nc2, err := nats.Connect(s.ClientURL(), nats.UserInfo("i", "i"), nats.CustomInboxPrefix("accI")) |
| 1042 | if err != nil { |
| 1043 | t.Fatalf("Error on connect: %v", err) |
| 1044 | } |
| 1045 | defer nc2.Close() |
nothing calls this directly
no test coverage detected