backport of commit dd0bdb1e0dff2e796ad7f0418e9128fe7d864362 (#17985)
This pull request was automerged via backport-assistant
This commit is contained in:
parent
46db1e76cb
commit
96934ce453
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package qemu
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/shoenig/test/must"
|
||||
)
|
||||
|
||||
func Test_taskStore(t *testing.T) {
|
||||
|
||||
taskStoreImpl := newTaskStore()
|
||||
must.NotNil(t, taskStoreImpl)
|
||||
|
||||
// Try reading something that doesn't exist.
|
||||
taskHandleResp1, okResp1 := taskStoreImpl.Get("this-doesn't-exist")
|
||||
must.Nil(t, taskHandleResp1)
|
||||
must.False(t, okResp1)
|
||||
|
||||
// Set and get a generated task handle.
|
||||
testTaskHandle := taskHandle{pid: 131313}
|
||||
taskStoreImpl.Set("test-id", &testTaskHandle)
|
||||
|
||||
taskHandleResp2, okResp2 := taskStoreImpl.Get("test-id")
|
||||
must.NotNil(t, taskHandleResp2)
|
||||
must.Eq(t, &testTaskHandle, taskHandleResp2)
|
||||
must.True(t, okResp2)
|
||||
|
||||
// Delete the previously set handle, and try reading it again.
|
||||
taskStoreImpl.Delete("test-id")
|
||||
|
||||
taskHandleResp3, okResp3 := taskStoreImpl.Get("test-id")
|
||||
must.Nil(t, taskHandleResp3)
|
||||
must.False(t, okResp3)
|
||||
|
||||
// Deleting a non-existent handle shouldn't cause any problems.
|
||||
taskStoreImpl.Delete("test-id")
|
||||
}
|
Loading…
Reference in New Issue