Skip to content

Commit 7a34d67

Browse files
committed
fix db queries tests, add a test there too
1 parent b18b726 commit 7a34d67

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

nexus/db-queries/src/db/queries/network_interface.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,7 @@ mod tests {
22052205
description: String::from("description"),
22062206
},
22072207
Some(requested_ip),
2208+
vec![],
22082209
)
22092210
.unwrap();
22102211
let err = context.datastore()
@@ -2234,6 +2235,7 @@ mod tests {
22342235
description: String::from("description"),
22352236
},
22362237
Some(requested_ip),
2238+
vec![],
22372239
)
22382240
.unwrap();
22392241
let inserted_interface = context
@@ -2266,6 +2268,7 @@ mod tests {
22662268
description: String::from("description"),
22672269
},
22682270
None,
2271+
vec![],
22692272
)
22702273
.unwrap();
22712274
let err = context.datastore()
@@ -2304,6 +2307,7 @@ mod tests {
23042307
description: String::from("description"),
23052308
},
23062309
None,
2310+
vec![],
23072311
)
23082312
.unwrap();
23092313
let inserted_interface = context
@@ -2348,6 +2352,7 @@ mod tests {
23482352
description: String::from("description"),
23492353
},
23502354
None,
2355+
vec![],
23512356
)
23522357
.unwrap();
23532358
let inserted_interface = context
@@ -2367,6 +2372,7 @@ mod tests {
23672372
description: String::from("description"),
23682373
},
23692374
Some(inserted_interface.ip.ip()),
2375+
vec![],
23702376
)
23712377
.unwrap();
23722378
let result = context
@@ -2615,6 +2621,7 @@ mod tests {
26152621
description: String::from("description"),
26162622
},
26172623
None,
2624+
vec![],
26182625
)
26192626
.unwrap();
26202627
let _ = context
@@ -2634,6 +2641,7 @@ mod tests {
26342641
description: String::from("description"),
26352642
},
26362643
None,
2644+
vec![],
26372645
)
26382646
.unwrap();
26392647
let result = context
@@ -2665,6 +2673,7 @@ mod tests {
26652673
description: String::from("description"),
26662674
},
26672675
None,
2676+
vec![],
26682677
)
26692678
.unwrap();
26702679
let _ = context
@@ -2681,6 +2690,7 @@ mod tests {
26812690
description: String::from("description"),
26822691
},
26832692
None,
2693+
vec![],
26842694
)
26852695
.unwrap();
26862696
let result = context
@@ -2709,6 +2719,7 @@ mod tests {
27092719
description: String::from("description"),
27102720
},
27112721
None,
2722+
vec![],
27122723
)
27132724
.unwrap();
27142725
let _ = context
@@ -2751,6 +2762,7 @@ mod tests {
27512762
description: String::from("description"),
27522763
},
27532764
None,
2765+
vec![],
27542766
)
27552767
.unwrap();
27562768
let _ = context
@@ -2769,6 +2781,7 @@ mod tests {
27692781
description: String::from("description"),
27702782
},
27712783
addr,
2784+
vec![],
27722785
)
27732786
.unwrap();
27742787
let result = context
@@ -2808,6 +2821,7 @@ mod tests {
28082821
description: String::from("description"),
28092822
},
28102823
None,
2824+
vec![],
28112825
)
28122826
.unwrap();
28132827
let _ = context
@@ -2837,6 +2851,7 @@ mod tests {
28372851
description: String::from("description"),
28382852
},
28392853
None,
2854+
vec![],
28402855
)
28412856
.unwrap();
28422857
let result = context
@@ -2870,6 +2885,7 @@ mod tests {
28702885
description: String::from("description"),
28712886
},
28722887
None,
2888+
vec![],
28732889
)
28742890
.unwrap();
28752891
let result = context
@@ -2914,6 +2930,7 @@ mod tests {
29142930
"The random MAC address {:?} is not a valid {} address",
29152931
inserted.mac, kind,
29162932
);
2933+
assert_eq!(inserted.transit_ips, incomplete.transit_ips);
29172934
}
29182935

29192936
// Test that we fail to insert an interface if there are no available slots
@@ -2938,6 +2955,7 @@ mod tests {
29382955
description: String::from("description"),
29392956
},
29402957
None,
2958+
vec![],
29412959
)
29422960
.unwrap();
29432961
let inserted_interface = context
@@ -2973,6 +2991,7 @@ mod tests {
29732991
description: String::from("description"),
29742992
},
29752993
None,
2994+
vec![],
29762995
)
29772996
.unwrap();
29782997
let result = context
@@ -3012,6 +3031,7 @@ mod tests {
30123031
description: String::from("description"),
30133032
},
30143033
None,
3034+
vec![],
30153035
)
30163036
.unwrap();
30173037
let intf = context
@@ -3039,6 +3059,7 @@ mod tests {
30393059
description: String::from("description"),
30403060
},
30413061
None,
3062+
vec![],
30423063
)
30433064
.unwrap();
30443065
let intf = context
@@ -3070,6 +3091,7 @@ mod tests {
30703091
description: String::from("description"),
30713092
},
30723093
None,
3094+
vec![],
30733095
)
30743096
.unwrap();
30753097
let intf = context
@@ -3113,6 +3135,7 @@ mod tests {
31133135
description: String::from("description"),
31143136
},
31153137
Some(IpAddr::V4(addr)),
3138+
vec![],
31163139
)
31173140
.unwrap();
31183141
let _ = context
@@ -3133,6 +3156,7 @@ mod tests {
31333156
description: String::from("description"),
31343157
},
31353158
None,
3159+
vec![],
31363160
)
31373161
.unwrap();
31383162

@@ -3187,4 +3211,62 @@ mod tests {
31873211
"fd00::ffff:ffff:ffff:fffe".parse::<IpAddr>().unwrap(),
31883212
);
31893213
}
3214+
3215+
#[tokio::test]
3216+
async fn test_insert_with_transit_ips() {
3217+
let context = TestContext::new("test_insert_with_transit_ips", 2).await;
3218+
let instance = context.create_stopped_instance().await;
3219+
let instance_id = InstanceUuid::from_untyped_uuid(instance.id());
3220+
3221+
// Create transit IPs to test with
3222+
let transit_ips = vec![
3223+
"10.0.0.0/24".parse().unwrap(),
3224+
"192.168.1.0/24".parse().unwrap(),
3225+
"172.16.0.0/16".parse().unwrap(),
3226+
];
3227+
3228+
let interface = IncompleteNetworkInterface::new_instance(
3229+
Uuid::new_v4(),
3230+
instance_id,
3231+
context.net1.subnets[0].clone(),
3232+
IdentityMetadataCreateParams {
3233+
name: "interface-with-transit".parse().unwrap(),
3234+
description: String::from("Test interface with transit IPs"),
3235+
},
3236+
None, // Auto-assign IP
3237+
transit_ips.clone(),
3238+
)
3239+
.unwrap();
3240+
3241+
let inserted_interface = context
3242+
.datastore()
3243+
.instance_create_network_interface_raw(
3244+
context.opctx(),
3245+
interface.clone(),
3246+
)
3247+
.await
3248+
.expect("Failed to insert interface with transit IPs");
3249+
3250+
// Verify the basic interface properties
3251+
assert_interfaces_eq(&interface, &inserted_interface.clone().into());
3252+
3253+
// Verify transit IPs are correctly persisted
3254+
assert_eq!(
3255+
inserted_interface.transit_ips.len(),
3256+
transit_ips.len(),
3257+
"Transit IPs count should match"
3258+
);
3259+
3260+
for (actual, expected) in
3261+
inserted_interface.transit_ips.iter().zip(transit_ips.iter())
3262+
{
3263+
assert_eq!(
3264+
actual, expected,
3265+
"Transit IP {} should match expected {}",
3266+
actual, expected
3267+
);
3268+
}
3269+
3270+
context.success().await;
3271+
}
31903272
}

nexus/src/app/sagas/instance_create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ async fn create_default_primary_network_interface(
682682
},
683683
vpc_name: default_name.clone(),
684684
subnet_name: default_name.clone(),
685-
ip: None, // Request an IP address allocation
685+
ip: None, // Request an IP address allocation
686686
transit_ips: vec![], // Default interfaces don't use transit IPs
687687
};
688688

nexus/tests/integration_tests/instances.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,10 @@ async fn test_instance_create_delete_network_interface(
26702670
vpc_name: "default".parse().unwrap(),
26712671
subnet_name: "default".parse().unwrap(),
26722672
ip: Some("172.30.0.10".parse().unwrap()),
2673-
transit_ips: vec!["10.0.0.0/24".parse().unwrap(), "10.1.0.0/24".parse().unwrap()],
2673+
transit_ips: vec![
2674+
"10.0.0.0/24".parse().unwrap(),
2675+
"10.1.0.0/24".parse().unwrap(),
2676+
],
26742677
},
26752678
params::InstanceNetworkInterfaceCreate {
26762679
identity: IdentityMetadataCreateParams {
@@ -2736,7 +2739,9 @@ async fn test_instance_create_delete_network_interface(
27362739
);
27372740
// Verify transit_ips are persisted correctly
27382741
assert_eq!(iface.transit_ips.len(), params.transit_ips.len());
2739-
for (actual, expected) in iface.transit_ips.iter().zip(params.transit_ips.iter()) {
2742+
for (actual, expected) in
2743+
iface.transit_ips.iter().zip(params.transit_ips.iter())
2744+
{
27402745
assert_eq!(actual, expected);
27412746
}
27422747
interfaces.push(iface);

0 commit comments

Comments
 (0)