Commit 1a0e42a
Shreyansh Sancheti
controller/vm: add comprehensive unit tests for VM Controller
Add 42 test cases covering:
- State.String() for all states including unknown/negative values
- TerminateVM state transitions (idempotency, success, error, recovery)
- Guard checks for all state-dependent methods with error content validation
- ExecIntoHost validation, success, non-zero exit code, and exec error paths
- DumpStacks with supported/unsupported capabilities and dump error path
- StartTime for all states
- ExitStatus success and error cases (table-driven)
- StartVM idempotency and error states (table-driven)
Follows Go test best practices:
- Table-driven tests with t.Run() and / separator for subtest names
- t.Parallel() on all subtests for concurrent execution
- defer ctrl.Finish() per repo convention (TestLookupVMMEM pattern)
- t.Context() instead of context.Background() (Go 1.24+)
- t.Errorf for independent assertions, t.Fatalf only for nil guards
- Error content validation (not just err != nil)
Signed-off-by: Shreyansh Sancheti <shreyanshjain7174@gmail.com>
Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>1 parent d4cbf06 commit 1a0e42a
4 files changed
Lines changed: 881 additions & 0 deletions
File tree
- internal
- controller/vm
- test/mock/vmcontroller
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments