chore: establish local platform baseline
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package device
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFirmwareAssignmentProgress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input CommandAcknowledgement
|
||||
wantStatus string
|
||||
wantProgress int
|
||||
wantProgressOK bool
|
||||
}{
|
||||
{
|
||||
name: "download progress",
|
||||
input: CommandAcknowledgement{Status: "ACKNOWLEDGED", ResultSummary: map[string]any{"phase": "downloading", "progress_percent": float64(25)}},
|
||||
wantStatus: "DOWNLOADING",
|
||||
wantProgress: 25,
|
||||
wantProgressOK: true,
|
||||
},
|
||||
{
|
||||
name: "install progress",
|
||||
input: CommandAcknowledgement{Status: "ACKNOWLEDGED", ResultSummary: map[string]any{"phase": "installing", "progress_percent": float64(80)}},
|
||||
wantStatus: "INSTALLING",
|
||||
wantProgress: 80,
|
||||
wantProgressOK: true,
|
||||
},
|
||||
{
|
||||
name: "reboot health verification remains installing",
|
||||
input: CommandAcknowledgement{Status: "ACKNOWLEDGED", ResultSummary: map[string]any{"phase": "boot_verifying", "progress_percent": float64(95)}},
|
||||
wantStatus: "INSTALLING",
|
||||
wantProgress: 95,
|
||||
wantProgressOK: true,
|
||||
},
|
||||
{
|
||||
name: "negative progress is clamped",
|
||||
input: CommandAcknowledgement{Status: "ACKNOWLEDGED", ResultSummary: map[string]any{"phase": "downloading", "progress_percent": float64(-2)}},
|
||||
wantStatus: "DOWNLOADING",
|
||||
wantProgress: 0,
|
||||
wantProgressOK: true,
|
||||
},
|
||||
{
|
||||
name: "oversized progress is clamped",
|
||||
input: CommandAcknowledgement{Status: "ACKNOWLEDGED", ResultSummary: map[string]any{"phase": "installing", "progress_percent": float64(101)}},
|
||||
wantStatus: "INSTALLING",
|
||||
wantProgress: 100,
|
||||
wantProgressOK: true,
|
||||
},
|
||||
{
|
||||
name: "success confirms assignment",
|
||||
input: CommandAcknowledgement{Status: "SUCCEEDED", ResultSummary: map[string]any{"installed_version": "2.3.1"}},
|
||||
wantStatus: "CONFIRMED",
|
||||
wantProgress: 100,
|
||||
wantProgressOK: true,
|
||||
},
|
||||
{
|
||||
name: "failure marks assignment failed",
|
||||
input: CommandAcknowledgement{Status: "FAILED", ResultSummary: map[string]any{"error": "checksum mismatch"}},
|
||||
wantStatus: "FAILED",
|
||||
},
|
||||
{
|
||||
name: "unknown acknowledgement phase is ignored",
|
||||
input: CommandAcknowledgement{Status: "ACKNOWLEDGED", ResultSummary: map[string]any{"phase": "restarting"}},
|
||||
wantStatus: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
status, progress := firmwareAssignmentProgress(tt.input)
|
||||
if status != tt.wantStatus {
|
||||
t.Fatalf("status = %q, want %q", status, tt.wantStatus)
|
||||
}
|
||||
if tt.wantProgressOK {
|
||||
if progress == nil || *progress != tt.wantProgress {
|
||||
t.Fatalf("progress = %v, want %d", progress, tt.wantProgress)
|
||||
}
|
||||
return
|
||||
}
|
||||
if progress != nil {
|
||||
t.Fatalf("progress = %d, want nil", *progress)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user