ryerraguntla commented on code in PR #3519:
URL: https://github.com/apache/iggy/pull/3519#discussion_r3812632094


##########
gateways/kafka/tests/version_firewall_tests.rs:
##########
@@ -0,0 +1,742 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Version negotiation firewall - boundary tests for every scoped API key.
+
+#[path = "common/codec.rs"]
+mod codec;
+#[path = "common/fixtures.rs"]
+mod fixtures;
+#[path = "common/scope.rs"]
+mod scope;
+#[path = "common/server.rs"]
+mod server;
+#[path = "common/tcp.rs"]
+mod tcp;
+#[path = "common/wire.rs"]
+mod wire;
+
+use std::time::Duration;
+
+use bytes::Bytes;
+use tokio::io::AsyncWriteExt;
+use tokio::net::TcpStream;
+
+use iggy_gateway_kafka::protocol::api::{
+    API_KEY_API_VERSIONS, API_KEY_CREATE_TOPICS, API_KEY_FETCH, 
API_KEY_LIST_OFFSETS,
+    API_KEY_METADATA, API_KEY_PRODUCE, ERROR_INVALID_REQUEST, ERROR_NONE,
+    ERROR_UNSUPPORTED_VERSION, advertised_min_version, handle_request, 
is_supported_version,
+    supported_api_ranges,
+};
+
+use codec::Decoder;
+use fixtures::{fixture_exists, load_fixture_body, load_fixture_body_or_skip};
+use scope::{SCOPED_API_KEYS, default_broker};
+use server::spawn_test_server;
+use tcp::{
+    ByteRead, build_list_offsets_v0_request_with_topic_t, 
build_metadata_legacy_request,
+    build_produce_flexible_body, build_produce_v2_body, build_produce_v3_body, 
build_request_frame,
+    parse_response_payload, read_byte_with_timeout, round_trip, 
scan_for_error_code,
+};
+use wire::{
+    OUT_OF_SCOPE_API_KEYS, build_api_versions_flexible_request, 
build_create_topics_empty_request,
+    build_fetch_empty_topics_request, build_list_offsets_request,
+    build_metadata_all_topics_flexible, build_metadata_all_topics_legacy,
+    build_metadata_flexible_request_v10,
+};
+
+#[test]
+fn supported_ranges_table_has_six_entries() {
+    assert_eq!(supported_api_ranges().len(), 6);
+}
+
+#[test]
+fn is_supported_version_matches_scope_table() {
+    for &(api_key, _, min_ver, max_ver) in SCOPED_API_KEYS {
+        assert!(
+            !is_supported_version(api_key, min_ver - 1),
+            "key {api_key} must reject v{}",
+            min_ver - 1
+        );
+        assert!(
+            is_supported_version(api_key, min_ver),
+            "key {api_key} must accept min v{min_ver}"
+        );
+        assert!(
+            is_supported_version(api_key, max_ver),
+            "key {api_key} must accept max v{max_ver}"
+        );
+        assert!(
+            !is_supported_version(api_key, max_ver + 1),
+            "key {api_key} must reject v{}",
+            max_ver + 1
+        );
+    }
+}
+
+#[test]
+fn apiversions_advertises_exact_supported_ranges_v1() {
+    let body = handle_request(API_KEY_API_VERSIONS, 1, Bytes::new(), 
&default_broker())
+        .expect_response("test request has acks != 0 and expects a response");
+    let mut d = Decoder::new(body);
+    assert_eq!(d.read_i16().unwrap(), 0);
+    let count = usize::try_from(d.read_i32().unwrap()).expect("api count fits 
usize");
+    assert_eq!(count, supported_api_ranges().len());
+
+    for expected in supported_api_ranges() {
+        let key = d.read_i16().unwrap();
+        let min = d.read_i16().unwrap();
+        let max = d.read_i16().unwrap();
+        assert_eq!(key, expected.api_key);
+        assert_eq!(

Review Comment:
   Both tests now compare against independent SCOPED_API_KEYS, not 
supported_api_ranges() itself (version_firewall_tests.rs:104, :132). Missing 
byte-exact v3 golden added:
     golden_apiversions_v3_flexible_response_fixture 
(golden_wire_fixtures_tests.rs).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to