Skip to content

Conversation

@lilyLuLiu
Copy link
Contributor

@lilyLuLiu lilyLuLiu commented Nov 12, 2025

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for multi-VM initialization and lifecycle management
    • Enhanced testing for concurrent VM creation, startup, and operations

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Walkthrough

New end-to-end test file for multi-VM initialization and lifecycle management in Macadam CLI. Tests VM creation, listing, starting, and SSH access verification across multiple VMs. Also adds a Name field to the ListReporter struct.

Changes

Cohort / File(s) Summary
Multi-VM lifecycle test suite
test/e2e/multipleVM_test.go
New test file with "Macadam init setup test" group. BeforeEach validates empty VM state; AfterEach cleans up all VMs. Test creates two CentOS VMs (vm1, vm2), starts them, verifies SSH access with "core" user, and confirms vm1 remains running. Uses JSON unmarshalling for VM enumeration and response validation.
ListReporter struct extension
test/e2e/vm_test.go
Adds public Name field of type string to the ListReporter struct.

Sequence Diagram

sequenceDiagram
    participant Test
    participant CLI as Macadam CLI
    participant VMs as VM System

    Test->>CLI: List VMs (BeforeEach)
    CLI->>VMs: Query VMs
    VMs-->>CLI: 0 VMs (JSON)
    CLI-->>Test: Success

    rect rgb(200, 220, 255)
    Note over Test,VMs: Test Execution
    Test->>CLI: Init vm1 (CentOS)
    CLI->>VMs: Create vm1
    VMs-->>CLI: Success
    
    Test->>CLI: List VMs
    CLI-->>Test: 1 VM
    
    Test->>CLI: Start vm1
    CLI->>VMs: Start vm1
    VMs-->>CLI: Success
    
    Test->>CLI: SSH vm1
    CLI->>VMs: SSH connection
    VMs-->>CLI: User: "core"
    
    Test->>CLI: Init vm2 (CentOS)
    CLI->>VMs: Create vm2
    VMs-->>CLI: Success
    
    Test->>CLI: Start vm2
    CLI->>VMs: Start vm2
    VMs-->>CLI: Success
    
    Test->>CLI: SSH vm2
    CLI->>VMs: SSH connection
    VMs-->>CLI: User: "core"
    
    Test->>CLI: SSH vm1 (verify still running)
    CLI->>VMs: SSH connection
    VMs-->>CLI: User: "core"
    end

    rect rgb(220, 200, 220)
    Note over Test,VMs: Cleanup (AfterEach)
    Test->>CLI: List all VMs
    CLI-->>Test: 2 VMs
    
    Test->>CLI: Stop & Remove all VMs
    CLI->>VMs: Remove vm1, vm2
    VMs-->>CLI: Success
    
    Test->>CLI: List VMs (verify empty)
    CLI-->>Test: 0 VMs
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify multi-VM test lifecycle logic (BeforeEach/AfterEach setup and teardown)
  • Confirm JSON unmarshalling handles variable VM counts correctly
  • Ensure SSH access verification reliably detects "core" user across multiple VMs
  • Validate struct field addition does not break existing ListReporter usage

Suggested reviewers

  • lstocchi

Poem

🐰 Two VMs now hop through our test,
Multiple machines put to the quest,
SSH bounds from vm1 to vm2 with cheer,
The Macadam warren grows clear! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding test cases for handling multiple VMs, which aligns with the new multipleVM_test.go file and ListReporter struct modification.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/e2e/multipleVM_test.go (1)

32-33: Remove unnecessary type conversion.

The string() conversion is unnecessary since m.Name is already declared as string in the ListReporter struct.

Apply this diff to simplify the code:

-			stopCmd := "stop " + string(m.Name)
-			rmCmd := "rm -f " + string(m.Name)
+			stopCmd := "stop " + m.Name
+			rmCmd := "rm -f " + m.Name
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46045de and c57d780.

📒 Files selected for processing (2)
  • test/e2e/multipleVM_test.go (1 hunks)
  • test/e2e/vm_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/e2e/multipleVM_test.go (2)
vendor/github.com/onsi/ginkgo/v2/core_dsl.go (4)
  • Describe (514-516)
  • BeforeEach (726-728)
  • AfterEach (754-756)
  • It (573-575)
vendor/github.com/onsi/gomega/gomega_dsl.go (1)
  • Expect (220-223)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test (windows-latest)
  • GitHub Check: lint
  • GitHub Check: test (macos-13)
  • GitHub Check: e2e (ubuntu-24.04)
🔇 Additional comments (4)
test/e2e/vm_test.go (1)

14-14: LGTM! Name field enables multi-VM test scenarios.

The addition of the Name field to the ListReporter struct is appropriate and necessary for identifying individual VMs in the new multi-VM test cases. The field is correctly used in test/e2e/multipleVM_test.go for cleanup operations.

test/e2e/multipleVM_test.go (3)

55-111: Excellent multi-VM test coverage.

The test case comprehensively validates multi-VM functionality including initialization with names, listing verification at each stage, concurrent VM operation, and SSH access to both VMs. The final check (lines 107-110) confirming vm1 remains accessible after vm2 is started is particularly valuable for verifying concurrent multi-VM operation.


15-22: Dismiss review comment; code is correct.

The referenced code is correct. Package-level variables machineResponses and err are properly declared in test/e2e/setup_test.go (lines 19-20). The snippet shows err := json.Unmarshal(...) using the short declaration operator as expected in Go, contradicting the review comment's claim that it lacks :=.

Likely an incorrect or invalid review comment.


12-12: Remove the review comment - it is based on incorrect analysis.

The image variable is properly declared at package level in test/e2e/setup_test.go line 21 and initialized in BeforeSuite() (lines 31-33). In Go, package-level variables declared in one file are accessible to all files in the same package. The commented-out declaration in multipleVM_test.go line 12 is redundant but causes no errors—the variable is accessible from setup_test.go where it's properly initialized before tests run.

Likely an incorrect or invalid review comment.

Comment on lines +86 to +92
// check the list command returns one item
session = macadamTest.Macadam([]string{"list", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
err = json.Unmarshal(session.Out.Contents(), &machineResponses)
Expect(err).NotTo(HaveOccurred())
Expect(len(machineResponses)).Should(Equal(2))
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix inaccurate comment.

The comment on line 86 states "returns one item" but the expectation on line 92 correctly checks for 2 items (vm1 and vm2).

Apply this diff to fix the comment:

-		// check the list command returns one item
+		// check the list command returns two items
 		session = macadamTest.Macadam([]string{"list", "--format", "json"})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// check the list command returns one item
session = macadamTest.Macadam([]string{"list", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
err = json.Unmarshal(session.Out.Contents(), &machineResponses)
Expect(err).NotTo(HaveOccurred())
Expect(len(machineResponses)).Should(Equal(2))
// check the list command returns two items
session = macadamTest.Macadam([]string{"list", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
err = json.Unmarshal(session.Out.Contents(), &machineResponses)
Expect(err).NotTo(HaveOccurred())
Expect(len(machineResponses)).Should(Equal(2))
🤖 Prompt for AI Agents
In test/e2e/multipleVM_test.go around lines 86 to 92, the inline comment
incorrectly says "returns one item" while the test asserts
Expect(len(machineResponses)).Should(Equal(2)); update the comment to accurately
reflect that the list command should return two items (vm1 and vm2) or remove
the comment; ensure the comment matches the expectation and test intent.

@lilyLuLiu lilyLuLiu self-assigned this Nov 12, 2025
@lilyLuLiu lilyLuLiu moved this to Work In Progress in Project planning: crc Nov 12, 2025
Copy link
Collaborator

@lstocchi lstocchi left a comment

Choose a reason for hiding this comment

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

As you're reusing the Before/After Suite added in setup_test.go I would move that common logic in common_test.go. It would be more logical from my pov for someone who look at the tests.

Setup_test.go could be misinterpreted ... it could refer to the tests related to setting up (init) a machine (which is what I thought in the prev PR). Now I see that it could also be interpreted like this file contains all code that setup things needed for running tests, but then I would separate the common before/after suite with the actual init command test logic. As we already have common_test.go we could use that instead.

"github.com/onsi/gomega/gexec"
)

//var image string
Copy link
Collaborator

Choose a reason for hiding this comment

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

to be removed

Comment on lines +15 to +22
BeforeEach(func() {
session := macadamTest.Macadam([]string{"list", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
err := json.Unmarshal(session.Out.Contents(), &machineResponses)
Expect(err).NotTo(HaveOccurred())
Expect(len(machineResponses)).Should(Equal(0))
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is the same code as in setup_test.go, could this be moved in the common_test.go?

Comment on lines +24 to +53
AfterEach(func() {
session := macadamTest.Macadam([]string{"list", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
err = json.Unmarshal(session.Out.Contents(), &machineResponses)
Expect(err).NotTo(HaveOccurred())

for _, m := range machineResponses {
stopCmd := "stop " + string(m.Name)
rmCmd := "rm -f " + string(m.Name)

// stop the CentOS VM
session = macadamTest.Macadam(strings.Fields(stopCmd))
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
Expect(session.OutputToString()).Should(ContainSubstring("stopped successfully"))

// rm the CentOS VM and verify that "list" does not return any vm
session = macadamTest.Macadam(strings.Fields(rmCmd))
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
}

session = macadamTest.Macadam([]string{"list", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
err = json.Unmarshal(session.Out.Contents(), &machineResponses)
Expect(err).NotTo(HaveOccurred())
Expect(len(machineResponses)).Should(Equal(0))
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above. This is very similar to the one in setup_test.go, maybe we could unify them in common_test.go so to not repeat it in every file?

Comment on lines +75 to +79
// ssh into the VM1 and prints user
session = macadamTest.Macadam([]string{"ssh", "vm1", "whoami"})
session.WaitWithDefaultTimeout()
Expect(session).Should(gexec.Exit(0))
Expect(session.OutputToString()).Should(Equal("core"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is also done at the end of the file. Is it a duplicate to be removed?

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

Labels

None yet

Projects

Status: Work In Progress

Development

Successfully merging this pull request may close these issues.

2 participants