Files
kata-containers/virtcontainers/factory/template/template_test.go
James O. D. Hunt d0679a6fd1 tracing: Add tracing support to virtcontainers
Add additional `context.Context` parameters and `struct` fields to allow
trace spans to be created by the `virtcontainers` internal functions,
objects and sub-packages.

Note that not every function is traced; we can add more traces as
desired.

Fixes #566.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2018-08-22 08:24:58 +01:00

74 lines
1.2 KiB
Go

// Copyright (c) 2018 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package template
import (
"context"
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
vc "github.com/kata-containers/runtime/virtcontainers"
)
func TestTemplateFactory(t *testing.T) {
assert := assert.New(t)
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
hyperConfig := vc.HypervisorConfig{
KernelPath: testDir,
ImagePath: testDir,
}
vmConfig := vc.VMConfig{
HypervisorType: vc.MockHypervisor,
AgentType: vc.NoopAgentType,
HypervisorConfig: hyperConfig,
}
ctx := context.Background()
// New
f := New(ctx, vmConfig)
// Config
assert.Equal(f.Config(), vmConfig)
// GetBaseVM
_, err := f.GetBaseVM(ctx)
assert.Nil(err)
// Fetch
tt := template{
statePath: testDir,
config: vmConfig,
}
err = tt.checkTemplateVM()
assert.Error(err)
_, err = os.Create(tt.statePath + "/memory")
assert.Nil(err)
err = tt.checkTemplateVM()
assert.Error(err)
_, err = os.Create(tt.statePath + "/state")
assert.Nil(err)
err = tt.checkTemplateVM()
assert.Nil(err)
err = tt.createTemplateVM(ctx)
assert.Nil(err)
_, err = tt.GetBaseVM(ctx)
assert.Nil(err)
// CloseFactory
f.CloseFactory(ctx)
tt.CloseFactory(ctx)
}