github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/experimental/experimental_test.go (about) 1 // Copyright (c) 2019 Huawei Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package experimental 7 8 import ( 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestExperimental(t *testing.T) { 15 f := Feature{ 16 Name: "mock", 17 Description: "mock experimental feature for test", 18 ExpRelease: "2.0", 19 } 20 assert.Nil(t, Get(f.Name)) 21 22 err := Register(f) 23 assert.Nil(t, err) 24 25 err = Register(f) 26 assert.NotNil(t, err) 27 assert.Equal(t, len(supportedFeatures), 1) 28 29 assert.NotNil(t, Get(f.Name)) 30 } 31 32 func TestValidateFeature(t *testing.T) { 33 f := Feature{} 34 assert.NotNil(t, validateFeature(f)) 35 36 for _, names := range []struct { 37 name string 38 valid bool 39 }{ 40 {"mock_test_1", true}, 41 {"m1234ock_test_1", true}, 42 {"1_mock_test", false}, 43 {"_mock_test_1", false}, 44 {"Mock", false}, 45 {"mock*&", false}, 46 } { 47 f := Feature{ 48 Name: names.name, 49 Description: "test", 50 ExpRelease: "2.0", 51 } 52 53 err := validateFeature(f) 54 if names.valid { 55 assert.Nil(t, err) 56 } else { 57 assert.NotNil(t, err) 58 } 59 } 60 }