external_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package external
  14. import (
  15. "testing"
  16. "github.com/stretchr/testify/assert"
  17. "k8s.io/apimachinery/pkg/util/sets"
  18. "k8s.io/kubernetes/test/e2e/framework/volume"
  19. "k8s.io/kubernetes/test/e2e/storage/testsuites"
  20. )
  21. func TestDriverParameter(t *testing.T) {
  22. expected := &driverDefinition{
  23. DriverInfo: testsuites.DriverInfo{
  24. Name: "foo.example.com",
  25. SupportedFsType: sets.NewString(
  26. "", // Default fsType
  27. ),
  28. },
  29. SupportedSizeRange: volume.SizeRange{
  30. Min: "5Gi",
  31. },
  32. }
  33. testcases := []struct {
  34. name string
  35. filename string
  36. err string
  37. expected *driverDefinition
  38. }{
  39. {
  40. name: "no such file",
  41. filename: "no-such-file.yaml",
  42. err: "open no-such-file.yaml: no such file or directory",
  43. },
  44. {
  45. name: "empty file name",
  46. err: "missing file name",
  47. },
  48. {
  49. name: "yaml",
  50. filename: "testdata/driver.yaml",
  51. expected: expected,
  52. },
  53. {
  54. name: "json",
  55. filename: "testdata/driver.json",
  56. expected: expected,
  57. },
  58. }
  59. for _, testcase := range testcases {
  60. actual, err := loadDriverDefinition(testcase.filename)
  61. if testcase.err == "" {
  62. assert.NoError(t, err, testcase.name)
  63. } else {
  64. if assert.Error(t, err, testcase.name) {
  65. assert.Equal(t, testcase.err, err.Error())
  66. }
  67. }
  68. if err == nil {
  69. assert.Equal(t, testcase.expected, actual)
  70. }
  71. }
  72. }