Skip to content

Commit

Permalink
backport of commit dd0bdb1 (#17985)
Browse files Browse the repository at this point in the history
This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-nomad-core authored Jul 19, 2023
1 parent 28094c9 commit 96d8bad
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions drivers/qemu/state_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 96d8bad

Please sign in to comment.