github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/sandboxlist_test.go (about) 1 // Copyright (c) 2018 HyperHQ Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package virtcontainers 7 8 import ( 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestSandboxListOperations(t *testing.T) { 15 p := &Sandbox{id: "testsandboxListsandbox"} 16 l := &sandboxList{sandboxes: make(map[string]*Sandbox)} 17 err := l.addSandbox(p) 18 assert.Nil(t, err, "addSandbox failed") 19 20 err = l.addSandbox(p) 21 assert.NotNil(t, err, "add same sandbox should fail") 22 23 np, err := l.lookupSandbox(p.id) 24 assert.Nil(t, err, "lookupSandbox failed") 25 assert.Equal(t, np, p, "lookupSandbox returns different sandbox %v:%v", np, p) 26 27 _, err = l.lookupSandbox("some-non-existing-sandbox-name") 28 assert.NotNil(t, err, "lookupSandbox for non-existing sandbox should fail") 29 30 l.removeSandbox(p.id) 31 }