github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/device/drivers/generic_test.go (about) 1 // Copyright (c) 2018 Huawei Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package drivers 7 8 import ( 9 "testing" 10 11 "github.com/kata-containers/runtime/virtcontainers/device/config" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestBumpAttachCount(t *testing.T) { 16 type testData struct { 17 attachCount uint 18 expectedAC uint 19 attach bool 20 expectSkip bool 21 expectErr bool 22 } 23 24 data := []testData{ 25 {0, 1, true, false, false}, 26 {1, 2, true, true, false}, 27 {intMax, intMax, true, true, true}, 28 {0, 0, false, true, true}, 29 {1, 0, false, false, false}, 30 {intMax, intMax - 1, false, true, false}, 31 } 32 33 dev := &GenericDevice{} 34 for _, d := range data { 35 dev.AttachCount = d.attachCount 36 skip, err := dev.bumpAttachCount(d.attach) 37 assert.Equal(t, skip, d.expectSkip, "") 38 assert.Equal(t, dev.GetAttachCount(), d.expectedAC, "") 39 if d.expectErr { 40 assert.NotNil(t, err) 41 } else { 42 assert.Nil(t, err) 43 } 44 } 45 } 46 47 func TestGetHostPath(t *testing.T) { 48 assert := assert.New(t) 49 dev := &GenericDevice{} 50 assert.Empty(dev.GetHostPath()) 51 52 expectedHostPath := "/dev/null" 53 dev.DeviceInfo = &config.DeviceInfo{ 54 HostPath: expectedHostPath, 55 } 56 assert.Equal(expectedHostPath, dev.GetHostPath()) 57 }