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