fix test for CheckpointStateRestore

This commit is contained in:
cncal 2022-01-21 12:53:08 +08:00
parent 7380fc735a
commit a64b9cee21

View File

@ -225,16 +225,20 @@ func TestCheckpointStateRestore(t *testing.T) {
} }
restoredState, err := NewCheckpointState(testingDir, testingCheckpoint, tc.policyName, tc.initialContainers) restoredState, err := NewCheckpointState(testingDir, testingCheckpoint, tc.policyName, tc.initialContainers)
if strings.TrimSpace(tc.expectedError) == "" {
if err != nil { if err != nil {
if strings.TrimSpace(tc.expectedError) != "" { t.Fatalf("unexpected error while creating checkpointState: %v", err)
}
} else {
if err == nil {
t.Fatalf("expected error: %s, got nil", tc.expectedError)
}
if strings.Contains(err.Error(), "could not restore state from checkpoint") && if strings.Contains(err.Error(), "could not restore state from checkpoint") &&
strings.Contains(err.Error(), tc.expectedError) { strings.Contains(err.Error(), tc.expectedError) {
t.Logf("got expected error: %v", err) t.Logf("got expected error: %v", err)
return return
} }
} }
t.Fatalf("unexpected error while creatng checkpointState: %v", err)
}
// compare state after restoration with the one expected // compare state after restoration with the one expected
AssertStateEqual(t, restoredState, tc.expectedState) AssertStateEqual(t, restoredState, tc.expectedState)