|
| 1 | +from natsrpy.js import ( |
| 2 | + AckPolicy, |
| 3 | + Compression, |
| 4 | + DeliverPolicy, |
| 5 | + DiscardPolicy, |
| 6 | + KVConfig, |
| 7 | + ObjectStoreConfig, |
| 8 | + PersistenceMode, |
| 9 | + PullConsumerConfig, |
| 10 | + PushConsumerConfig, |
| 11 | + ReplayPolicy, |
| 12 | + Republish, |
| 13 | + RetentionPolicy, |
| 14 | + StorageType, |
| 15 | + StreamConfig, |
| 16 | +) |
| 17 | + |
| 18 | + |
| 19 | +async def test_storage_type_values() -> None: |
| 20 | + assert StorageType.FILE is not None |
| 21 | + assert StorageType.MEMORY is not None |
| 22 | + assert StorageType.FILE != StorageType.MEMORY |
| 23 | + |
| 24 | + |
| 25 | +async def test_discard_policy_values() -> None: |
| 26 | + assert DiscardPolicy.OLD is not None |
| 27 | + assert DiscardPolicy.NEW is not None |
| 28 | + assert DiscardPolicy.OLD != DiscardPolicy.NEW |
| 29 | + |
| 30 | + |
| 31 | +async def test_retention_policy_values() -> None: |
| 32 | + assert RetentionPolicy.LIMITS is not None |
| 33 | + assert RetentionPolicy.INTEREST is not None |
| 34 | + assert RetentionPolicy.WORKQUEUE is not None |
| 35 | + |
| 36 | + |
| 37 | +async def test_compression_values() -> None: |
| 38 | + assert Compression.S2 is not None |
| 39 | + assert Compression.NONE is not None |
| 40 | + assert Compression.S2 != Compression.NONE |
| 41 | + |
| 42 | + |
| 43 | +async def test_persistence_mode_values() -> None: |
| 44 | + assert PersistenceMode.Default is not None |
| 45 | + assert PersistenceMode.Async is not None |
| 46 | + |
| 47 | + |
| 48 | +async def test_deliver_policy_values() -> None: |
| 49 | + assert DeliverPolicy.ALL is not None |
| 50 | + assert DeliverPolicy.LAST is not None |
| 51 | + assert DeliverPolicy.NEW is not None |
| 52 | + assert DeliverPolicy.BY_START_SEQUENCE is not None |
| 53 | + assert DeliverPolicy.BY_START_TIME is not None |
| 54 | + assert DeliverPolicy.LAST_PER_SUBJECT is not None |
| 55 | + |
| 56 | + |
| 57 | +async def test_ack_policy_values() -> None: |
| 58 | + assert AckPolicy.EXPLICIT is not None |
| 59 | + assert AckPolicy.NONE is not None |
| 60 | + assert AckPolicy.ALL is not None |
| 61 | + |
| 62 | + |
| 63 | +async def test_replay_policy_values() -> None: |
| 64 | + assert ReplayPolicy.INSTANT is not None |
| 65 | + assert ReplayPolicy.ORIGINAL is not None |
| 66 | + |
| 67 | + |
| 68 | +async def test_stream_config_defaults() -> None: |
| 69 | + config = StreamConfig(name="test", subjects=["test.>"]) |
| 70 | + assert config.name == "test" |
| 71 | + assert config.subjects == ["test.>"] |
| 72 | + |
| 73 | + |
| 74 | +async def test_stream_config_setters() -> None: |
| 75 | + config = StreamConfig(name="test", subjects=["test.>"]) |
| 76 | + config.name = "new-name" |
| 77 | + assert config.name == "new-name" |
| 78 | + config.subjects = ["new.>"] |
| 79 | + assert config.subjects == ["new.>"] |
| 80 | + config.description = "a description" |
| 81 | + assert config.description == "a description" |
| 82 | + |
| 83 | + |
| 84 | +async def test_stream_config_all_options() -> None: |
| 85 | + config = StreamConfig( |
| 86 | + name="full-test", |
| 87 | + subjects=["full.>"], |
| 88 | + max_bytes=1024, |
| 89 | + max_messages=100, |
| 90 | + max_messages_per_subject=10, |
| 91 | + discard=DiscardPolicy.NEW, |
| 92 | + retention=RetentionPolicy.WORKQUEUE, |
| 93 | + max_consumers=5, |
| 94 | + storage=StorageType.MEMORY, |
| 95 | + num_replicas=1, |
| 96 | + no_ack=False, |
| 97 | + description="full config", |
| 98 | + allow_rollup=False, |
| 99 | + deny_delete=False, |
| 100 | + deny_purge=False, |
| 101 | + allow_direct=True, |
| 102 | + ) |
| 103 | + assert config.name == "full-test" |
| 104 | + assert config.subjects == ["full.>"] |
| 105 | + assert config.max_bytes == 1024 |
| 106 | + assert config.max_messages == 100 |
| 107 | + assert config.max_messages_per_subject == 10 |
| 108 | + assert config.discard == DiscardPolicy.NEW |
| 109 | + assert config.retention == RetentionPolicy.WORKQUEUE |
| 110 | + assert config.max_consumers == 5 |
| 111 | + assert config.storage == StorageType.MEMORY |
| 112 | + assert config.num_replicas == 1 |
| 113 | + assert config.description == "full config" |
| 114 | + assert config.allow_direct is True |
| 115 | + |
| 116 | + |
| 117 | +async def test_pull_consumer_config_defaults() -> None: |
| 118 | + config = PullConsumerConfig() |
| 119 | + assert config.name is None |
| 120 | + assert config.durable_name is None |
| 121 | + assert config.description is None |
| 122 | + |
| 123 | + |
| 124 | +async def test_pull_consumer_config_setters() -> None: |
| 125 | + config = PullConsumerConfig(name="test-consumer") |
| 126 | + config.name = "updated-name" |
| 127 | + assert config.name == "updated-name" |
| 128 | + config.description = "updated description" |
| 129 | + assert config.description == "updated description" |
| 130 | + |
| 131 | + |
| 132 | +async def test_pull_consumer_config_policies() -> None: |
| 133 | + config = PullConsumerConfig( |
| 134 | + ack_policy=AckPolicy.ALL, |
| 135 | + deliver_policy=DeliverPolicy.LAST, |
| 136 | + replay_policy=ReplayPolicy.ORIGINAL, |
| 137 | + ) |
| 138 | + assert config.ack_policy == AckPolicy.ALL |
| 139 | + assert config.deliver_policy == DeliverPolicy.LAST |
| 140 | + assert config.replay_policy == ReplayPolicy.ORIGINAL |
| 141 | + |
| 142 | + |
| 143 | +async def test_push_consumer_config_defaults() -> None: |
| 144 | + config = PushConsumerConfig(deliver_subject="test.subject") |
| 145 | + assert config.deliver_subject == "test.subject" |
| 146 | + assert config.name is None |
| 147 | + |
| 148 | + |
| 149 | +async def test_push_consumer_config_setters() -> None: |
| 150 | + config = PushConsumerConfig(deliver_subject="test.subject") |
| 151 | + config.deliver_subject = "new.subject" |
| 152 | + assert config.deliver_subject == "new.subject" |
| 153 | + config.name = "push-consumer" |
| 154 | + assert config.name == "push-consumer" |
| 155 | + |
| 156 | + |
| 157 | +async def test_kv_config_defaults() -> None: |
| 158 | + config = KVConfig(bucket="test-bucket") |
| 159 | + assert config.bucket == "test-bucket" |
| 160 | + assert config.description is None |
| 161 | + |
| 162 | + |
| 163 | +async def test_kv_config_setters() -> None: |
| 164 | + config = KVConfig(bucket="test-bucket") |
| 165 | + config.bucket = "new-bucket" |
| 166 | + assert config.bucket == "new-bucket" |
| 167 | + config.description = "test desc" |
| 168 | + assert config.description == "test desc" |
| 169 | + config.history = 5 |
| 170 | + assert config.history == 5 |
| 171 | + |
| 172 | + |
| 173 | +async def test_kv_config_all_options() -> None: |
| 174 | + config = KVConfig( |
| 175 | + bucket="full-kv", |
| 176 | + description="full kv config", |
| 177 | + history=10, |
| 178 | + storage=StorageType.MEMORY, |
| 179 | + num_replicas=1, |
| 180 | + ) |
| 181 | + assert config.bucket == "full-kv" |
| 182 | + assert config.description == "full kv config" |
| 183 | + assert config.history == 10 |
| 184 | + assert config.storage == StorageType.MEMORY |
| 185 | + assert config.num_replicas == 1 |
| 186 | + |
| 187 | + |
| 188 | +async def test_object_store_config_defaults() -> None: |
| 189 | + config = ObjectStoreConfig(bucket="test-bucket") |
| 190 | + assert config.bucket == "test-bucket" |
| 191 | + assert config.description is None |
| 192 | + |
| 193 | + |
| 194 | +async def test_object_store_config_setters() -> None: |
| 195 | + config = ObjectStoreConfig(bucket="test-bucket") |
| 196 | + config.bucket = "new-bucket" |
| 197 | + assert config.bucket == "new-bucket" |
| 198 | + config.description = "test desc" |
| 199 | + assert config.description == "test desc" |
| 200 | + |
| 201 | + |
| 202 | +async def test_republish_config() -> None: |
| 203 | + r = Republish(source="src.>", destination="dest.>", headers_only=False) |
| 204 | + assert r.source == "src.>" |
| 205 | + assert r.destination == "dest.>" |
| 206 | + assert r.headers_only is False |
| 207 | + |
| 208 | + r.source = "new.src.>" |
| 209 | + assert r.source == "new.src.>" |
| 210 | + r.destination = "new.dest.>" |
| 211 | + assert r.destination == "new.dest.>" |
| 212 | + r.headers_only = True |
| 213 | + assert r.headers_only is True |
0 commit comments