| 1 |
//go:build windows |
| 2 |
// +build windows |
| 3 |
|
| 4 |
/* |
| 5 |
Copyright 2017 The Kubernetes Authors. |
| 6 |
|
| 7 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
you may not use this file except in compliance with the License. |
| 9 |
You may obtain a copy of the License at |
| 10 |
|
| 11 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
|
| 13 |
Unless required by applicable law or agreed to in writing, software |
| 14 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
See the License for the specific language governing permissions and |
| 17 |
limitations under the License. |
| 18 |
*/ |
| 19 |
|
| 20 |
package mount |
| 21 |
|
| 22 |
import ( |
| 23 |
"testing" |
| 24 |
) |
| 25 |
|
| 26 |
func TestNormalizeWindowsPath(t *testing.T) { |
| 27 |
path := `/var/lib/kubelet/pods/146f8428-83e7-11e7-8dd4-000d3a31dac4/volumes/kubernetes.io~azure-disk` |
| 28 |
normalizedPath := NormalizeWindowsPath(path) |
| 29 |
if normalizedPath != `c:\var\lib\kubelet\pods\146f8428-83e7-11e7-8dd4-000d3a31dac4\volumes\kubernetes.io~azure-disk` { |
| 30 |
t.Errorf("normizeWindowsPath test failed, normalizedPath : %q", normalizedPath) |
| 31 |
} |
| 32 |
|
| 33 |
path = `/var/lib/kubelet/pods/146f8428-83e7-11e7-8dd4-000d3a31dac4\volumes\kubernetes.io~azure-disk` |
| 34 |
normalizedPath = NormalizeWindowsPath(path) |
| 35 |
if normalizedPath != `c:\var\lib\kubelet\pods\146f8428-83e7-11e7-8dd4-000d3a31dac4\volumes\kubernetes.io~azure-disk` { |
| 36 |
t.Errorf("normizeWindowsPath test failed, normalizedPath : %q", normalizedPath) |
| 37 |
} |
| 38 |
|
| 39 |
path = `/` |
| 40 |
normalizedPath = NormalizeWindowsPath(path) |
| 41 |
if normalizedPath != `c:\` { |
| 42 |
t.Errorf("normizeWindowsPath test failed, normalizedPath : %q", normalizedPath) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func TestValidateDiskNumber(t *testing.T) { |
| 47 |
diskNum := "0" |
| 48 |
if err := ValidateDiskNumber(diskNum); err != nil { |
| 49 |
t.Errorf("TestValidateDiskNumber test failed, disk number : %s", diskNum) |
| 50 |
} |
| 51 |
|
| 52 |
diskNum = "99" |
| 53 |
if err := ValidateDiskNumber(diskNum); err != nil { |
| 54 |
t.Errorf("TestValidateDiskNumber test failed, disk number : %s", diskNum) |
| 55 |
} |
| 56 |
|
| 57 |
diskNum = "ab" |
| 58 |
if err := ValidateDiskNumber(diskNum); err == nil { |
| 59 |
t.Errorf("TestValidateDiskNumber test failed, disk number : %s", diskNum) |
| 60 |
} |
| 61 |
|
| 62 |
diskNum = "100" |
| 63 |
if err := ValidateDiskNumber(diskNum); err == nil { |
| 64 |
t.Errorf("TestValidateDiskNumber test failed, disk number : %s", diskNum) |
| 65 |
} |
| 66 |
} |