Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qemu: add test to cover task store functions. #17967

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}