mirror of
https://github.com/containerd/containerd.git
synced 2026-08-09 09:33:06 +00:00
This commit makes all of the recommended changes to use the `testing` package helper functions instead of doing the equivalent longhand versions of the same thing. This change was needed in order to properly detect errors, as the code would previously skip running `tenv` stating that it had been deprecated in favor of `usetesting`. Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
/*
|
|
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 runtime
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
criconfig "github.com/containerd/containerd/v2/internal/cri/config"
|
|
"github.com/containerd/containerd/v2/pkg/oci"
|
|
)
|
|
|
|
func TestLoadBaseOCISpec(t *testing.T) {
|
|
spec := oci.Spec{Version: "1.0.2", Hostname: "default"}
|
|
|
|
file, err := os.Create(filepath.Join(t.TempDir(), "spec-test-"))
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
file.Close()
|
|
})
|
|
|
|
err = json.NewEncoder(file).Encode(&spec)
|
|
assert.NoError(t, err)
|
|
|
|
config := criconfig.Config{}
|
|
config.Runtimes = map[string]criconfig.Runtime{
|
|
"runc": {BaseRuntimeSpec: file.Name()},
|
|
}
|
|
|
|
specs, err := loadBaseOCISpecs(&config)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, specs, 1)
|
|
|
|
out, ok := specs[file.Name()]
|
|
assert.True(t, ok, "expected spec with file name %q", file.Name())
|
|
|
|
assert.Equal(t, "1.0.2", out.Version)
|
|
assert.Equal(t, "default", out.Hostname)
|
|
}
|