command: Clean up testInputResponseMap before failing on unused answers

If you don't, the unused answers will persist in the package-level var
and bleed in to other tests.
This commit is contained in:
Chris Arcand 2021-09-22 15:55:56 -05:00
parent 60bc7aa05d
commit 171cdbbf93
1 changed files with 6 additions and 3 deletions

View File

@ -716,12 +716,15 @@ func testInputMap(t *testing.T, answers map[string]string) func() {
// Return the cleanup
return func() {
if len(testInputResponseMap) > 0 {
t.Fatalf("expected no unused answers provided to command.testInputMap, got: %v", testInputResponseMap)
}
var unusedAnswers = testInputResponseMap
// First, clean up!
test = true
testInputResponseMap = nil
if len(unusedAnswers) > 0 {
t.Fatalf("expected no unused answers provided to command.testInputMap, got: %v", unusedAnswers)
}
}
}