forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_test.go
60 lines (50 loc) · 1007 Bytes
/
check_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCheckValid(t *testing.T) {
assert := assert.New(t)
type testData struct {
value string
valid bool
}
data := []testData{
{"", true},
{" ", true},
{"\t", true},
{"\n", true},
{`\t`, true},
{`\n`, true},
{"\x00", false},
{"\x11", false},
{"hello\x00", false},
{"hello\x00world", false},
{"\x00hello", false},
{"world\x00", false},
{`\x00`, true},
{`\x11`, true},
{"%!d(MISSING)", false},
{"%!f(MISSING)", false},
{"%!v(MISSING)", false},
{"%!(BADINDEX)", false},
{"%!(BADPREC)", false},
{"%!(BADWIDTH)", false},
{"%!(EXTRA ", false},
{"%!(EXTRA ", false},
{"%!(EXTRA string=hello)", false},
}
for i, d := range data {
err := checkValid(d.value)
if d.valid {
assert.NoErrorf(err, "test[%d]: %+v", i, d)
} else {
assert.Errorf(err, "test[%d]: %+v", i, d)
}
}
}