external_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/storage/testsuites"
  19. )
  20. func TestDriverParameter(t *testing.T) {
  21. expected := &driverDefinition{
  22. DriverInfo: testsuites.DriverInfo{
  23. Name: "foo.example.com",
  24. SupportedFsType: sets.NewString(
  25. "", // Default fsType
  26. ),
  27. },
  28. ShortName: "foo",
  29. ClaimSize: "5Gi",
  30. }
  31. testcases := []struct {
  32. name string
  33. filename string
  34. err string
  35. expected *driverDefinition
  36. }{
  37. {
  38. name: "no such file",
  39. filename: "no-such-file.yaml",
  40. err: "open no-such-file.yaml: no such file or directory",
  41. },
  42. {
  43. name: "empty file name",
  44. err: "missing file name",
  45. },
  46. {
  47. name: "yaml",
  48. filename: "testdata/driver.yaml",
  49. expected: expected,
  50. },
  51. {
  52. name: "json",
  53. filename: "testdata/driver.json",
  54. expected: expected,
  55. },
  56. }
  57. for _, testcase := range testcases {
  58. actual, err := testDriverParameter{}.loadDriverDefinition(testcase.filename)
  59. if testcase.err == "" {
  60. assert.NoError(t, err, testcase.name)
  61. } else {
  62. if assert.Error(t, err, testcase.name) {
  63. assert.Equal(t, testcase.err, err.Error())
  64. }
  65. }
  66. if err == nil {
  67. assert.Equal(t, testcase.expected, actual)
  68. }
  69. }
  70. }