backport of commit dd0bdb1e0dff2e796ad7f0418e9128fe7d864362 (#17985)

This pull request was automerged via backport-assistant
This commit is contained in:
hc-github-team-nomad-core 2023-07-19 09:35:46 -05:00 committed by GitHub
parent 46db1e76cb
commit 96934ce453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 0 deletions

View File

@ -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")
}