Files
kubernetes/test/e2e/storage/external/external_test.go
Patrick Ohly 6644db9914 e2e/storage: testing of external storage drivers
It is useful to apply the storage testsuite also to "external" (=
out-of-tree) storage drivers. One way of doing that is setting up a
custom E2E test suite, but that's still quite a bit of work.

An easier alternative is to parameterize the Kubernetes e2e.test
binary at runtime so that it instantiates the testsuite for one or
more drivers. Some parameters have to be provided before starting the
test because they define configuration and capabilities of the driver
and its storage backend that cannot be discovered at runtime. This is
done by populating the DriverDefinition with the content of the file
that the new -storage.testdriver parameters points to.

The universal .yaml and .json decoder from Kubernetes is used. It's
flexible, but has some downsides:
- currently ignores unknown fields (see https://github.com/kubernetes/kubernetes/pull/71589)
- poor error messages when fields have the wrong type

Storage drivers have to be installed in the test cluster before
starting e2e.test. Only tests involving dynamically provisioned
volumes are currently supported.
2019-03-06 22:06:31 +01:00

80 lines
1.8 KiB
Go

/*
Copyright 2019 The Kubernetes 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 external
import (
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/test/e2e/storage/testsuites"
)
func TestDriverParameter(t *testing.T) {
expected := &driverDefinition{
DriverInfo: testsuites.DriverInfo{
Name: "foo.example.com",
SupportedFsType: sets.NewString(
"", // Default fsType
),
},
ShortName: "foo",
ClaimSize: "5Gi",
}
testcases := []struct {
name string
filename string
err string
expected *driverDefinition
}{
{
name: "no such file",
filename: "no-such-file.yaml",
err: "open no-such-file.yaml: no such file or directory",
},
{
name: "empty file name",
err: "missing file name",
},
{
name: "yaml",
filename: "testdata/driver.yaml",
expected: expected,
},
{
name: "json",
filename: "testdata/driver.json",
expected: expected,
},
}
for _, testcase := range testcases {
actual, err := testDriverParameter{}.loadDriverDefinition(testcase.filename)
if testcase.err == "" {
assert.NoError(t, err, testcase.name)
} else {
if assert.Error(t, err, testcase.name) {
assert.Equal(t, testcase.err, err.Error())
}
}
if err == nil {
assert.Equal(t, testcase.expected, actual)
}
}
}