Skip to content

Commit 2df29b7

Browse files
committed
Adding tigron tests
Signed-off-by: apostasie <[email protected]>
1 parent c57654b commit 2df29b7

File tree

4 files changed

+262
-2
lines changed

4 files changed

+262
-2
lines changed
+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package require_test
18+
19+
import (
20+
"runtime"
21+
"testing"
22+
23+
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
24+
"github.com/containerd/nerdctl/mod/tigron/require"
25+
)
26+
27+
const (
28+
darwin = "darwin"
29+
windows = "windows"
30+
linux = "linux"
31+
)
32+
33+
func TestRequire(t *testing.T) {
34+
t.Parallel()
35+
36+
var pass bool
37+
38+
switch runtime.GOOS {
39+
case "windows":
40+
pass, _ = require.Windows.Check(nil, nil)
41+
case "linux":
42+
pass, _ = require.Linux.Check(nil, nil)
43+
case "darwin":
44+
pass, _ = require.Darwin.Check(nil, nil)
45+
default:
46+
pass, _ = require.OS(runtime.GOOS).Check(nil, nil)
47+
}
48+
49+
assertive.IsEqual(t, pass, true)
50+
51+
switch runtime.GOARCH {
52+
case "amd64":
53+
pass, _ = require.Amd64.Check(nil, nil)
54+
case "arm64":
55+
pass, _ = require.Arm64.Check(nil, nil)
56+
default:
57+
pass, _ = require.Arch(runtime.GOARCH).Check(nil, nil)
58+
}
59+
60+
assertive.IsEqual(t, pass, true)
61+
}
62+
63+
func TestNot(t *testing.T) {
64+
t.Parallel()
65+
66+
var pass bool
67+
68+
switch runtime.GOOS {
69+
case windows:
70+
pass, _ = require.Not(require.Linux).Check(nil, nil)
71+
case linux:
72+
pass, _ = require.Not(require.Windows).Check(nil, nil)
73+
case darwin:
74+
pass, _ = require.Not(require.Windows).Check(nil, nil)
75+
default:
76+
pass, _ = require.Not(require.Linux).Check(nil, nil)
77+
}
78+
79+
assertive.IsEqual(t, pass, true)
80+
}
81+
82+
func TestAllSuccess(t *testing.T) {
83+
t.Parallel()
84+
85+
var pass bool
86+
87+
switch runtime.GOOS {
88+
case windows:
89+
pass, _ = require.All(require.Not(require.Linux), require.Not(require.Darwin)).
90+
Check(nil, nil)
91+
case linux:
92+
pass, _ = require.All(require.Not(require.Windows), require.Not(require.Darwin)).
93+
Check(nil, nil)
94+
case darwin:
95+
pass, _ = require.All(require.Not(require.Windows), require.Not(require.Linux)).
96+
Check(nil, nil)
97+
default:
98+
pass, _ = require.All(require.Not(require.Windows), require.Not(require.Linux),
99+
require.Not(require.Darwin)).Check(nil, nil)
100+
}
101+
102+
assertive.IsEqual(t, pass, true)
103+
}
104+
105+
func TestAllOneFail(t *testing.T) {
106+
t.Parallel()
107+
108+
var pass bool
109+
110+
switch runtime.GOOS {
111+
case "windows":
112+
pass, _ = require.All(require.Not(require.Linux), require.Not(require.Darwin)).
113+
Check(nil, nil)
114+
case "linux":
115+
pass, _ = require.All(require.Not(require.Windows), require.Not(require.Darwin)).
116+
Check(nil, nil)
117+
case "darwin":
118+
pass, _ = require.All(require.Not(require.Windows), require.Not(require.Linux)).
119+
Check(nil, nil)
120+
default:
121+
pass, _ = require.All(require.Not(require.OS(runtime.GOOS)), require.Not(require.Linux),
122+
require.Not(require.Darwin)).Check(nil, nil)
123+
}
124+
125+
assertive.IsEqual(t, pass, true)
126+
}

mod/tigron/test/config_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//nolint:testpackage
18+
package test
19+
20+
import (
21+
"testing"
22+
23+
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
24+
)
25+
26+
func TestConfig(t *testing.T) {
27+
t.Parallel()
28+
29+
// Create
30+
cfg := WithConfig("test", "something")
31+
32+
assertive.IsEqual(t, string(cfg.Read("test")), "something")
33+
34+
// Write
35+
cfg.Write("test-write", "else")
36+
37+
// Overwrite
38+
cfg.Write("test", "one")
39+
40+
assertive.IsEqual(t, string(cfg.Read("test")), "one")
41+
assertive.IsEqual(t, string(cfg.Read("test-write")), "else")
42+
43+
assertive.IsEqual(t, string(cfg.Read("doesnotexist")), "")
44+
45+
// Test adoption
46+
cfg2 := WithConfig("test", "two")
47+
cfg2.Write("adopt", "two")
48+
49+
//nolint:forcetypeassert
50+
cfg.(*config).adopt(cfg2)
51+
52+
assertive.IsEqual(t, string(cfg.Read("test")), "one")
53+
assertive.IsEqual(t, string(cfg.Read("adopt")), "two")
54+
}

mod/tigron/test/data_test.go

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//nolint:testpackage
18+
package test
19+
20+
import (
21+
"testing"
22+
23+
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
24+
)
25+
26+
func TestDataBasic(t *testing.T) {
27+
t.Parallel()
28+
29+
dataObj := WithData("test", "create")
30+
31+
assertive.IsEqual(t, dataObj.Get("test"), "create")
32+
assertive.IsEqual(t, dataObj.Get("doesnotexist"), "")
33+
34+
dataObj.Set("test", "set")
35+
assertive.IsEqual(t, dataObj.Get("test"), "set")
36+
}
37+
38+
func TestDataTempDir(t *testing.T) {
39+
t.Parallel()
40+
41+
dataObj := configureData(t, nil, nil)
42+
43+
one := dataObj.TempDir()
44+
two := dataObj.TempDir()
45+
46+
assertive.IsEqual(t, one, two)
47+
assertive.IsNotEqual(t, one, "")
48+
}
49+
50+
func TestDataIdentifier(t *testing.T) {
51+
t.Parallel()
52+
53+
dataObj := configureData(t, nil, nil)
54+
55+
one := dataObj.Identifier()
56+
two := dataObj.Identifier()
57+
58+
assertive.IsEqual(t, one, two)
59+
assertive.StringHasPrefix(t, one, "testdataidentifier")
60+
61+
three := dataObj.Identifier("Some Add ∞ Funky∞Prefix")
62+
assertive.StringHasPrefix(t, three, "testdataidentifier-some-add-funky-prefix")
63+
}
64+
65+
func TestDataIdentifierThatIsReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLong(
66+
t *testing.T,
67+
) {
68+
t.Parallel()
69+
70+
dataObj := configureData(t, nil, nil)
71+
72+
one := dataObj.Identifier()
73+
two := dataObj.Identifier()
74+
75+
assertive.IsEqual(t, one, two)
76+
assertive.StringHasPrefix(t, one, "testdataidentifier")
77+
assertive.IsEqual(t, len(one), identifierMaxLength)
78+
79+
three := dataObj.Identifier("Add something")
80+
assertive.IsNotEqual(t, three, one)
81+
}

mod/tigron/test/interfaces.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import (
2626
// Data is meant to hold information about a test:
2727
// - first, any random key value data that the test implementer wants to carry / modify - this is
2828
// test data - second, some commonly useful immutable test properties (a way to generate unique
29-
// identifiers for that test,
30-
// temporary directory, etc.)
29+
// identifiers for that test, temporary directory, etc.)
3130
// Note that Data is inherited, from parent test to subtest (except for Identifier and TempDir of
3231
// course).
3332
type Data interface {

0 commit comments

Comments
 (0)