Do not rename test files on-the-fly to share functions
Instead this commit moves some functions that could be used by fuzzers. Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
parent
49a945b26b
commit
f318947b06
@ -90,11 +90,4 @@ sed -i 's/\/run\/containerd-test/\/tmp\/containerd-test/g' $SRC/containerd/integ
|
||||
|
||||
cd integration/client
|
||||
|
||||
# Rename all *_test.go to *_test_fuzz.go to use their declarations:
|
||||
for i in $( ls *_test.go ); do mv $i ./${i%.*}_fuzz.go; done
|
||||
|
||||
# Remove windows test to avoid double declarations:
|
||||
rm ./client_windows_test_fuzz.go
|
||||
rm ./helpers_windows_test_fuzz.go
|
||||
|
||||
compile_fuzzers '^func FuzzInteg.*data' compile_go_fuzzer vendor
|
||||
|
74
integration/client/client.go
Normal file
74
integration/client/client.go
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/defaults"
|
||||
"github.com/containerd/containerd/log/logtest"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
)
|
||||
|
||||
const (
|
||||
testNamespace = "testing"
|
||||
)
|
||||
|
||||
var (
|
||||
address string
|
||||
ctrdStdioFilePath string
|
||||
testSnapshotter = containerd.DefaultSnapshotter
|
||||
ctrd = &daemon{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&address, "address", defaults.DefaultAddress, "The address to the containerd socket for use in the tests")
|
||||
}
|
||||
|
||||
func testContext(t testing.TB) (context.Context, context.CancelFunc) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx = namespaces.WithNamespace(ctx, testNamespace)
|
||||
if t != nil {
|
||||
ctx = logtest.WithT(ctx, t)
|
||||
}
|
||||
return ctx, cancel
|
||||
}
|
||||
|
||||
func createShimDebugConfig() string {
|
||||
f, err := os.CreateTemp("", "containerd-config-")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to create config file: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.WriteString("version = 2\n"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err := f.WriteString("[plugins.\"io.containerd.runtime.v1.linux\"]\n\tshim_debug = true\n"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return f.Name()
|
||||
}
|
@ -33,7 +33,6 @@ import (
|
||||
imagelist "github.com/containerd/containerd/integration/images"
|
||||
"github.com/containerd/containerd/leases"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/log/logtest"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/pkg/testutil"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
@ -45,32 +44,16 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
address string
|
||||
noDaemon bool
|
||||
noCriu bool
|
||||
supportsCriu bool
|
||||
testNamespace = "testing"
|
||||
testSnapshotter = DefaultSnapshotter
|
||||
ctrdStdioFilePath string
|
||||
|
||||
ctrd = &daemon{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&address, "address", defaultAddress, "The address to the containerd socket for use in the tests")
|
||||
flag.BoolVar(&noDaemon, "no-daemon", false, "Do not start a dedicated daemon for the tests")
|
||||
flag.BoolVar(&noCriu, "no-criu", false, "Do not run the checkpoint tests")
|
||||
}
|
||||
|
||||
func testContext(t testing.TB) (context.Context, context.CancelFunc) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx = namespaces.WithNamespace(ctx, testNamespace)
|
||||
if t != nil {
|
||||
ctx = logtest.WithT(ctx, t)
|
||||
}
|
||||
return ctx, cancel
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Parse()
|
||||
if testing.Short() {
|
||||
@ -507,26 +490,6 @@ func TestClientReconnect(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func createShimDebugConfig() string {
|
||||
f, err := os.CreateTemp("", "containerd-config-")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to create config file: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.WriteString("version = 2\n"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err := f.WriteString("[plugins.\"io.containerd.runtime.v1.linux\"]\n\tshim_debug = true\n"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return f.Name()
|
||||
}
|
||||
|
||||
func TestDefaultRuntimeWithNamespaceLabels(t *testing.T) {
|
||||
client, err := newClient(t, address)
|
||||
if err != nil {
|
||||
|
26
integration/client/client_unix.go
Normal file
26
integration/client/client_unix.go
Normal file
@ -0,0 +1,26 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
const (
|
||||
defaultRoot = "/var/lib/containerd-test"
|
||||
defaultState = "/run/containerd-test"
|
||||
defaultAddress = "/run/containerd-test/containerd.sock"
|
||||
)
|
@ -27,12 +27,6 @@ import (
|
||||
"github.com/containerd/containerd/platforms"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultRoot = "/var/lib/containerd-test"
|
||||
defaultState = "/run/containerd-test"
|
||||
defaultAddress = "/run/containerd-test/containerd.sock"
|
||||
)
|
||||
|
||||
var (
|
||||
testImage = images.Get(images.BusyBox)
|
||||
testMultiLayeredImage = images.Get(images.VolumeCopyUp)
|
||||
|
Loading…
Reference in New Issue
Block a user