Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/identifiers/validate_test.go
2610 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
// From https://github.com/containerd/containerd/blob/v2.1.1/pkg/identifiers/validate_test.go
5
// SPDX-FileCopyrightText: Copyright The containerd Authors
6
// LICENSE: https://github.com/containerd/containerd/blob/v2.1.1/LICENSE
7
// NOTICE: https://github.com/containerd/containerd/blob/v2.1.1/NOTICE
8
9
/*
10
Copyright The containerd Authors.
11
12
Licensed under the Apache License, Version 2.0 (the "License");
13
you may not use this file except in compliance with the License.
14
You may obtain a copy of the License at
15
16
http://www.apache.org/licenses/LICENSE-2.0
17
18
Unless required by applicable law or agreed to in writing, software
19
distributed under the License is distributed on an "AS IS" BASIS,
20
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
See the License for the specific language governing permissions and
22
limitations under the License.
23
*/
24
25
package identifiers
26
27
import (
28
"strings"
29
"testing"
30
31
"gotest.tools/v3/assert"
32
)
33
34
func TestValidIdentifiers(t *testing.T) {
35
for _, input := range []string{
36
"default",
37
"Default",
38
t.Name(),
39
"default-default",
40
"containerd.io",
41
"foo.boo",
42
"swarmkit.docker.io",
43
"0912341234",
44
"task.0.0123456789",
45
"container.system-75-f19a.00",
46
"underscores_are_allowed",
47
strings.Repeat("a", maxLength),
48
} {
49
t.Run(input, func(t *testing.T) {
50
assert.NilError(t, Validate(input))
51
})
52
}
53
}
54
55
func TestInvalidIdentifiers(t *testing.T) {
56
for _, input := range []string{
57
"",
58
".foo..foo",
59
"foo/foo",
60
"foo/..",
61
"foo..foo",
62
"foo.-boo",
63
"-foo.boo",
64
"foo.boo-",
65
"but__only_tasteful_underscores",
66
"zn--e9.org", // or something like it!
67
"default--default",
68
strings.Repeat("a", maxLength+1),
69
} {
70
t.Run(input, func(t *testing.T) {
71
assert.ErrorContains(t, Validate(input), "")
72
})
73
}
74
}
75
76