Repository navigation
Make test instance setup less repetitive - #11858
Conversation
Adds a builder for InstanceCreate bodies which I'll plug into a bunch of places next.
|
after putting up the draft I noticed another fifty places we |
|
Love it. Big fan of leaning on the helpers. The verbosity of our tests makes it so hard to understand which choices matter. |
instances.rs did different stuff with ssh key defaults than everything else..
| client, | ||
| PROJECT_NAME, | ||
| INSTANCE_NAME, | ||
| &Default::default(), |
There was a problem hiding this comment.
this was probably a bug in the test setup (which I think did not matter). an instance that is created in Stopped would get the default DefaultDualStack interface, rather than the DefaultIpv4 that create_instance() just above would use. I assume we should probably test with dual-stack subnets at this point but the tests but create_default_subnet_pool only sets up V4 test subnets. this is the case for all the create_instance_stopped() here.
| "instance {:?}", | ||
| instance.identity.name |
There was a problem hiding this comment.
for the most part I have tried to keep instance settings matching whatever they were before the refactor, but some of these were so funky I had a hard time convincing myself to care about a weird interim point. since name is a Name, the {:?} here would make the instance's description instance Name("just-rainsticks"). InstanceCreateBuilder's default description also formats with {:?}, but does so on the &str for the instance name, so this is "only" instance "just-rainsticks" now.
| @@ -3158,33 +3019,9 @@ async fn test_instances_create_stopped_start( | |||
| create_project_and_pool(&client).await; | |||
|
|
|||
| // Create an instance in a stopped state. | |||
| let instance: Instance = object_create( | |||
There was a problem hiding this comment.
create_instance_stopped is such an appropriate helper here I struggle to convince myself that it's wroth spelling out the old defaults, and this test obviously does not care about user data, SSH keys, etc.
| let interim_body = instance::InstanceCreate { | ||
| identity: IdentityMetadataCreateParams { | ||
| name: instance_name.parse().unwrap(), | ||
| description: format!("instance {:?}", instance_name), |
There was a problem hiding this comment.
I kind of wish this was instance {}, but that gets beyond what I was willing to tolerate in "largely refactoring".
| anti_affinity_groups: Vec::new(), | ||
| enable_jumbo_frames: false, | ||
| }; | ||
| .with_ssh_public_keys(None) |
There was a problem hiding this comment.
this test is where we actually care about None vs Some(vec![...]). other uses of .with_ssh_public_keys(None) are just to match a prior ssh_public_keys: None which itself was probably a copy-paste default.
anywhere outside this test I kind of think we should discard a ssh_public_keys setting (as well as with_user_data(&[])..) because really the test just wanted some kind of reasonable value to make the builder compile.
jmpesp
left a comment
There was a problem hiding this comment.
ship it ship it ship it ship it ship it
| pool: DEMO_IP_POOL_NAME.clone().into(), | ||
| }, | ||
| }]) | ||
| .with_start(true) |
There was a problem hiding this comment.
this was true before too, but: should this be creating a stopped instance instead?
There was a problem hiding this comment.
oh yes, this was the other "I think our tests do the wrong thing" that I had wanted to comment on. thank you for noticing. I think it should, but it I think it doesn't matter because we don't use these demo instances in ways that would care. I definitely didn't want to change it without more reading than I wanted to do in this diff.
| ncpus: instance.ncpus, | ||
| memory: instance.memory, |
There was a problem hiding this comment.
I wonder if it would help to have a InstanceCreateBuilder::from(&instance)? Maybe as follow up work, not to delay this PR.
There was a problem hiding this comment.
I think it's actually pretty rare that we want a carbon-copy of a specific instance's settings. here, I think this is because "we had an instance up there, this is shorter to type than the InstanceCpuCount and ByteCount::from_gibibytes invocations, end of". this test does care about the instance name matching, and that's about it really...
|
since you've both taken a look already (thanks!) I've fixed the conflict and will merge this as-is. there'll be a followup PR to move the |
when I added
cpu_platformsa while ago it was kind of sad how manyInstanceCreateI had to go touch, but I did because I wasn't sure how to spell it better at the time. as I'm going to be adding a new field imminently, I was looking at this again and got sad again because we've added a few more fields and clearly other folks were kind of sad about this same situation.so, hopefully this gets people away from having to ask, when reading a test: "did the test author pick a value they thought was a good default, did the author pick a value they needed for a test, or is this just copied from somewhere else?"
this will conflict with #11565, which also adds a field to
InstanceCreateand demonstrates my sadness. if #11565 goes first though, the resolution is probably straightforward: in all the places except where we're specifically testing the shutdown policy, take the default that this change introduces instead.