-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COCOS-365-Add igvm measurement #379
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #379 +/- ##
==========================================
- Coverage 59.57% 59.29% -0.29%
==========================================
Files 54 57 +3
Lines 4574 4761 +187
==========================================
+ Hits 2725 2823 +98
- Misses 1564 1640 +76
- Partials 285 298 +13 ☔ View full report in Codecov by Sentry. |
_, err := NewIgvmMeasurement("", nil, nil) | ||
if err == nil { | ||
t.Errorf("expected error for empty pathToFile, got nil") | ||
} | ||
|
||
igvm, err := NewIgvmMeasurement("/valid/path", nil, nil) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if igvm == nil { | ||
t.Errorf("expected non-nil IgvmMeasurement") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use assertions for expectations
func TestIgvmMeasurement_Run_Success(t *testing.T) { | ||
mockOutput := "measurement successful" // Ensure it's a **single-line output** | ||
|
||
m := &IgvmMeasurement{ | ||
pathToFile: "/valid/path", | ||
execCommand: func(name string, arg ...string) *exec.Cmd { | ||
cmd := exec.Command("sh", "-c", "echo '"+mockOutput+"'") // Single line output | ||
return cmd | ||
}, | ||
} | ||
|
||
err := m.Run("/mock/igvmBinary") | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
} | ||
} | ||
|
||
func TestIgvmMeasurement_Run_Error(t *testing.T) { | ||
mockOutput := "some error occurred" | ||
|
||
m := &IgvmMeasurement{ | ||
pathToFile: "/invalid/path", | ||
execCommand: func(name string, arg ...string) *exec.Cmd { | ||
cmd := exec.Command("sh", "-c", "echo '"+mockOutput+"' && echo 'extra line' && exit 1") // Simulate multiline error | ||
return cmd | ||
}, | ||
} | ||
|
||
err := m.Run("/mock/igvmBinary") | ||
|
||
if err == nil { | ||
t.Errorf("expected an error, got nil") | ||
} else if !strings.Contains(err.Error(), "error: "+mockOutput) { | ||
t.Errorf("expected error message to contain 'error: %s', got: %s", mockOutput, err) | ||
} | ||
} | ||
|
||
func TestIgvmMeasurement_Stop_NoProcess(t *testing.T) { | ||
m := &IgvmMeasurement{} | ||
|
||
err := m.Stop() | ||
if err == nil || err.Error() != "no running process to stop" { | ||
t.Errorf("expected 'no running process to stop' error, got: %v", err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combine tests into a single test with multiple test cases as we do for other tests
What type of PR is this?
This is a feature because it adds the following functionality: Igvm measurement functionality
What does this do?
Change the CLI so it calculates the measurement based on the vTPM and OVMF used.
Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
No, I have not included tests because I am waiting for the first review.
Did you document any new/modified feature?
No, I have not updated the documentation but I will focus on documentation next.