From 87ccd41af26f073cde7aaa74c049e85bdb2f89af Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 28 Nov 2019 11:33:35 +0100 Subject: [PATCH] e2e storage: add compile test for public TestSuite API This will catch accidentally adding a new interface function which isn't exported. For example, an attempt to implement a new unexported "foobar()" function then leads to: test/e2e/storage/testsuites/api_test.go:54:5: cannot use &fakeSuite literal (type *fakeSuite) as type testsuites.TestSuite in assignment: *fakeSuite does not implement testsuites.TestSuite (missing testsuites.foobar method) have foobar() want testsuites.foobar() FAIL k8s.io/kubernetes/test/e2e/storage/testsuites [build failed] --- test/e2e/storage/testsuites/api_test.go | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/e2e/storage/testsuites/api_test.go diff --git a/test/e2e/storage/testsuites/api_test.go b/test/e2e/storage/testsuites/api_test.go new file mode 100644 index 00000000000..11f3021aeaa --- /dev/null +++ b/test/e2e/storage/testsuites/api_test.go @@ -0,0 +1,52 @@ +/* +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 testsuites_test is used intentionally to ensure that the +// code below only has access to exported names. It doesn't have any +// actual test. That the custom volume test suite defined below +// compile is the test. +// +// It's needed because we don't have any in-tree volume test +// suite implementations that aren't in the "testuites" package itself. +// We don't need this for the "TestDriver" interface because there +// we have implementations in a separate package. +package testsuites_test + +import ( + "k8s.io/kubernetes/test/e2e/framework/volume" + "k8s.io/kubernetes/test/e2e/storage/testpatterns" + "k8s.io/kubernetes/test/e2e/storage/testsuites" +) + +type fakeSuite struct { +} + +func (f *fakeSuite) GetTestSuiteInfo() testsuites.TestSuiteInfo { + return testsuites.TestSuiteInfo{ + Name: "fake", + FeatureTag: "", + TestPatterns: []testpatterns.TestPattern{testpatterns.DefaultFsDynamicPV}, + SupportedSizeRange: volume.SizeRange{Min: "1Mi", Max: "1Gi"}, + } +} + +func (f *fakeSuite) DefineTests(testsuites.TestDriver, testpatterns.TestPattern) { +} + +func (f *fakeSuite) SkipRedundantSuite(testsuites.TestDriver, testpatterns.TestPattern) { +} + +var _ testsuites.TestSuite = &fakeSuite{}