TPT-4260 Implement integration tests for expand create linodes options and password less#944
Conversation
0a45a44 to
921ba51
Compare
921ba51 to
225979d
Compare
There was a problem hiding this comment.
Pull request overview
Adds new integration test coverage around Linode instance creation edge cases (password-less validation) and creating/rebuilding instances when Kernel and BootSize are provided.
Changes:
- Added a test asserting the API returns a 400 when
root_pass/authorized_keys/authorized_usersare all omitted. - Added an end-to-end style test that creates an instance with
Kernel+BootSize, creates a disk, and rebuilds the instance. - Introduced
testify/assertusage ininstances_test.gofor additional assertions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Kernel: linodego.Pointer("linode/latest-64bit"), | ||
| BootSize: linodego.Pointer(8192), | ||
| AuthorizedKeys: []string{"ssh-rsa"}, | ||
| }, |
There was a problem hiding this comment.
AuthorizedKeys: []string{"ssh-rsa"} is not a valid SSH public key (it’s missing the base64 key material). This will cause CreateInstance to fail when recording against the real API. Use a full public key string (e.g., reuse testSSHKeyCreateOpts.SSHKey from profile_sshkeys_test.go) or provide RootPass instead.
| Type: "g6-standard-2", | ||
| AuthorizedKeys: []string{"ecdsa-sha2-nistp"}, |
There was a problem hiding this comment.
AuthorizedKeys: []string{"ecdsa-sha2-nistp"} is not a valid SSH public key (it’s missing the curve + base64 key material). This will likely make RebuildInstance fail when fixtures are recorded. Use a complete SSH public key string (for example testSSHKeyCreateOpts.SSHKey) or set RootPass.
| Type: "g6-standard-2", | |
| AuthorizedKeys: []string{"ecdsa-sha2-nistp"}, | |
| Type: "g6-standard-2", | |
| RootPass: randPassword(), |
| }) | ||
| require.NoError(t, errCreateDisk) | ||
| assert.Equal(t, linodego.DiskNotReady, createDiskResponse.Status) | ||
|
|
There was a problem hiding this comment.
This test asserts the new disk is DiskNotReady and immediately proceeds to rebuild the instance. That means the disk create action is still in progress; depending on API behavior this can be flaky or rejected, and it can also make the deferred DeleteInstance fail due to an in-progress operation. Consider waiting for the disk create event (ActionDiskCreate) or WaitForInstanceDiskStatus(..., DiskReady, ...) before calling RebuildInstance (and/or before teardown).
| _, err = client.WaitForInstanceDiskStatus( | |
| context.Background(), | |
| instance.ID, | |
| createDiskResponse.ID, | |
| linodego.DiskReady, | |
| 180, | |
| ) | |
| require.NoErrorf(t, err, "Error waiting for disk ready: %s", err) |
ezilber-akamai
left a comment
There was a problem hiding this comment.
Tests pass locally. Nice work!
| region := getRegionsWithCapsAndSiteType( | ||
| t, | ||
| client, | ||
| []string{"Linodes", "Maintenance Policy"}, |
There was a problem hiding this comment.
Can we replace the hardcoded values with:
linodego.CapabilityLinodes and linodego.CapabilityMaintenancePolicy ?
There was a problem hiding this comment.
Good idea. Changed
| region := getRegionsWithCapsAndSiteType( | ||
| t, | ||
| client, | ||
| []string{"Linodes", "Maintenance Policy"}, |
✔️ How to Test
make TEST_ARGS="-run TestExpectedErrorIfFieldsAuthorizedUsersAuthorizedKeysRootPassAreNotSet"
make TEST_ARGS="-run TestCreateLinodeWithKernalAndBootSizeThenAddDiskAndRebuild"
TAG: cleo-slade-beta