attacher_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 azure_dd
  14. import (
  15. "fmt"
  16. "testing"
  17. "time"
  18. "github.com/stretchr/testify/assert"
  19. "k8s.io/api/core/v1"
  20. "k8s.io/kubernetes/pkg/volume"
  21. )
  22. func createVolSpec(name string, readOnly bool) *volume.Spec {
  23. return &volume.Spec{
  24. Volume: &v1.Volume{
  25. VolumeSource: v1.VolumeSource{
  26. AzureDisk: &v1.AzureDiskVolumeSource{
  27. DiskName: name,
  28. ReadOnly: &readOnly,
  29. },
  30. },
  31. },
  32. }
  33. }
  34. func TestWaitForAttach(t *testing.T) {
  35. tests := []struct {
  36. devicePath string
  37. expected string
  38. expectError bool
  39. }{
  40. {
  41. devicePath: "/dev/disk/azure/scsi1/lun0",
  42. expected: "/dev/disk/azure/scsi1/lun0",
  43. expectError: false,
  44. },
  45. {
  46. devicePath: "/dev/sdc",
  47. expected: "/dev/sdc",
  48. expectError: false,
  49. },
  50. {
  51. devicePath: "/dev/disk0",
  52. expected: "/dev/disk0",
  53. expectError: false,
  54. },
  55. }
  56. attacher := azureDiskAttacher{}
  57. spec := createVolSpec("fakedisk", false)
  58. for _, test := range tests {
  59. result, err := attacher.WaitForAttach(spec, test.devicePath, nil, 3000*time.Millisecond)
  60. assert.Equal(t, result, test.expected)
  61. assert.Equal(t, err != nil, test.expectError, fmt.Sprintf("error msg: %v", err))
  62. }
  63. }