(t *testing.T)
| 1496 | } |
| 1497 | |
| 1498 | func TestKeyValueRePublish(t *testing.T) { |
| 1499 | s := RunBasicJetStreamServer() |
| 1500 | defer shutdownJSServerAndRemoveStorage(t, s) |
| 1501 | |
| 1502 | nc, js := jsClient(t, s) |
| 1503 | defer nc.Close() |
| 1504 | |
| 1505 | if _, err := js.CreateKeyValue(&nats.KeyValueConfig{ |
| 1506 | Bucket: "TEST_UPDATE", |
| 1507 | }); err != nil { |
| 1508 | t.Fatalf("Error creating store: %v", err) |
| 1509 | } |
| 1510 | // This is expected to fail since server does not support as of now |
| 1511 | // the update of RePublish. |
| 1512 | if _, err := js.CreateKeyValue(&nats.KeyValueConfig{ |
| 1513 | Bucket: "TEST_UPDATE", |
| 1514 | RePublish: &nats.RePublish{Source: ">", Destination: "bar.>"}, |
| 1515 | }); err == nil { |
| 1516 | t.Fatal("Expected failure, did not get one") |
| 1517 | } |
| 1518 | |
| 1519 | kv, err := js.CreateKeyValue(&nats.KeyValueConfig{ |
| 1520 | Bucket: "TEST", |
| 1521 | RePublish: &nats.RePublish{Source: ">", Destination: "bar.>"}, |
| 1522 | }) |
| 1523 | if err != nil { |
| 1524 | t.Fatalf("Error creating store: %v", err) |
| 1525 | } |
| 1526 | si, err := js.StreamInfo("KV_TEST") |
| 1527 | if err != nil { |
| 1528 | t.Fatalf("Error getting stream info: %v", err) |
| 1529 | } |
| 1530 | if si.Config.RePublish == nil { |
| 1531 | t.Fatal("Expected republish to be set, it was not") |
| 1532 | } |
| 1533 | |
| 1534 | sub, err := nc.SubscribeSync("bar.>") |
| 1535 | if err != nil { |
| 1536 | t.Fatalf("Error on sub: %v", err) |
| 1537 | } |
| 1538 | if _, err := kv.Put("foo", []byte("value")); err != nil { |
| 1539 | t.Fatalf("Error on put: %v", err) |
| 1540 | } |
| 1541 | msg, err := sub.NextMsg(time.Second) |
| 1542 | if err != nil { |
| 1543 | t.Fatalf("Error on next: %v", err) |
| 1544 | } |
| 1545 | if v := string(msg.Data); v != "value" { |
| 1546 | t.Fatalf("Unexpected value: %s", v) |
| 1547 | } |
| 1548 | // The message should also have a header with the actual subject |
| 1549 | kvSubjectsPreTmpl := "$KV.%s." |
| 1550 | expected := fmt.Sprintf(kvSubjectsPreTmpl, "TEST") + "foo" |
| 1551 | if v := msg.Header.Get(nats.JSSubject); v != expected { |
| 1552 | t.Fatalf("Expected subject header %q, got %q", expected, v) |
| 1553 | } |
| 1554 | } |
| 1555 |
nothing calls this directly
no test coverage detected