Skip to content

Conversation

@psnoch-akamai
Copy link
Contributor

@psnoch-akamai psnoch-akamai commented Dec 18, 2025

✔️ How to Test

make TEST_ARGS="-run TestTryToLockTwoResourcesWithTheSameType"
make TEST_ARGS="-run TestTryToCreateWithInvalidData"

Copilot AI review requested due to automatic review settings December 18, 2025 15:57
@psnoch-akamai psnoch-akamai requested a review from a team as a code owner December 18, 2025 15:57
@psnoch-akamai psnoch-akamai requested review from ezilber-akamai, vshanthe and zliang-akamai and removed request for a team December 18, 2025 15:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two integration tests for the Resource lock functionality to verify error handling scenarios: attempting to create conflicting lock types on the same resource, and attempting to create a lock with an invalid entity ID.

Key Changes

  • Added TestTryToLockTwoResourcesWithTheSameType to verify that creating a second lock with a different lock type on the same resource produces an error
  • Added TestTryToCreateWithInvalidData to verify that attempting to create a lock with a non-existent entity ID returns the expected error message
  • Imported testify/assert and testify/require packages for improved test assertions

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/integration/locks_test.go Added two new test functions with testify assertions to validate lock creation error scenarios
test/integration/fixtures/TestLockTryToLockResourceTwice.yaml Added fixture data for testing conflicting lock types on the same resource
test/integration/fixtures/TestLockTryToCreateWithNotExistingEntityID.yaml Added fixture data for testing lock creation with an invalid entity ID

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


func TestTryToLockTwoResourcesWithTheSameType(t *testing.T) {
client, instance, _, teardown, err := setupInstanceWithoutDisks(t,
"fixtures/TestLockTryToLockResourceTwice", false)
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixture file name 'TestLockTryToLockResourceTwice' doesn't match the test function name 'TestTryToLockTwoResourcesWithTheSameType'. For consistency and maintainability, the fixture filename should match the test name.

Suggested change
"fixtures/TestLockTryToLockResourceTwice", false)
"fixtures/TestTryToLockTwoResourcesWithTheSameType", false)

Copilot uses AI. Check for mistakes.
Comment on lines 97 to 98
_, errAlreadyExist := client.CreateLock(context.Background(), createOpts)
require.Error(t, errAlreadyExist)
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name 'errAlreadyExist' is misleading. Based on the fixture response (line 574-576), the error is about conflicting lock types, not about a lock already existing. Consider renaming to 'errConflictingLock' or 'createSecondLockErr' for clarity.

Suggested change
_, errAlreadyExist := client.CreateLock(context.Background(), createOpts)
require.Error(t, errAlreadyExist)
_, errConflictingLock := client.CreateLock(context.Background(), createOpts)
require.Error(t, errConflictingLock)

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

func TestTryToCreateWithInvalidData(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLockTryToCreateWithNotExistingEntityID")
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixture filename 'TestLockTryToCreateWithNotExistingEntityID' is inconsistent with the test function name 'TestTryToCreateWithInvalidData'. The fixture should be named 'TestTryToCreateWithInvalidData.yaml' to maintain consistency between test names and their corresponding fixtures.

Suggested change
client, teardown := createTestClient(t, "fixtures/TestLockTryToCreateWithNotExistingEntityID")
client, teardown := createTestClient(t, "fixtures/TestTryToCreateWithInvalidData")

Copilot uses AI. Check for mistakes.
@psnoch-akamai psnoch-akamai force-pushed the TPT-4097-resource-lock-extra-integration-tests branch from ed420ff to 2a6b8eb Compare December 19, 2025 12:26

createdLock, err := client.CreateLock(context.Background(), createOpts)
require.NoError(t, err)
defer client.DeleteLock(context.Background(), createdLock.ID)
Copy link
Member

@zliang-akamai zliang-akamai Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defer client.DeleteLock(context.Background(), createdLock.ID)
t.Cleanup(func() {
client.DeleteLock(context.Background(), createdLock.ID)
})

Let's use t.Cleanup everywhere to ensure consistency and the order of executions of different deleting operations.


func TestTryToCreateWithInvalidData(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestTryToCreateWithInvalidData")
defer teardown()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defer teardown()
t.Cleanup(teardown)

LockType: linodego.LockTypeCannotDeleteWithSubresources,
}

_, createLockErr := client.CreateLock(context.Background(), createOpts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just use err variable naming for createLockErr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants