gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/factory/cache/cache_test.go (about)

     1  // Copyright (c) 2018 HyperHQ Inc.
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  
     6  package cache
     7  
     8  import (
     9  	"context"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  
    14  	vc "github.com/kata-containers/runtime/virtcontainers"
    15  	"github.com/kata-containers/runtime/virtcontainers/factory/direct"
    16  	"github.com/kata-containers/runtime/virtcontainers/persist/fs"
    17  )
    18  
    19  func TestTemplateFactory(t *testing.T) {
    20  	assert := assert.New(t)
    21  
    22  	testDir := fs.MockStorageRootPath()
    23  	defer fs.MockStorageDestroy()
    24  
    25  	hyperConfig := vc.HypervisorConfig{
    26  		KernelPath: testDir,
    27  		ImagePath:  testDir,
    28  	}
    29  	vmConfig := vc.VMConfig{
    30  		HypervisorType:   vc.MockHypervisor,
    31  		AgentType:        vc.NoopAgentType,
    32  		ProxyType:        vc.NoopProxyType,
    33  		HypervisorConfig: hyperConfig,
    34  	}
    35  
    36  	ctx := context.Background()
    37  
    38  	// New
    39  	f := New(ctx, 2, direct.New(ctx, vmConfig))
    40  
    41  	// Config
    42  	assert.Equal(f.Config(), vmConfig)
    43  
    44  	// GetBaseVM
    45  	vm, err := f.GetBaseVM(ctx, vmConfig)
    46  	assert.Nil(err)
    47  
    48  	err = vm.Stop()
    49  	assert.Nil(err)
    50  
    51  	// CloseFactory
    52  	f.CloseFactory(ctx)
    53  }