|
| 1 | +/* |
| 2 | +Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package importer |
| 18 | + |
| 19 | +import ( |
| 20 | + "runtime" |
| 21 | + "testing" |
| 22 | +) |
| 23 | + |
| 24 | +func TestImporter_manifestPath(t *testing.T) { |
| 25 | + // We can only test filepath operations on the target OS |
| 26 | + manifestTests := []struct { |
| 27 | + goos string |
| 28 | + name string |
| 29 | + path string |
| 30 | + expected string |
| 31 | + }{ |
| 32 | + { |
| 33 | + goos: "linux", |
| 34 | + name: "linux path", |
| 35 | + path: "/home/user/foo/bar/qux.ovf", |
| 36 | + expected: "/home/user/foo/bar/qux.mf", |
| 37 | + }, |
| 38 | + { |
| 39 | + goos: "darwin", |
| 40 | + name: "darwin path", |
| 41 | + path: "/home/user/foo/bar/qux.ovf", |
| 42 | + expected: "/home/user/foo/bar/qux.mf", |
| 43 | + }, |
| 44 | + { |
| 45 | + goos: "windows", |
| 46 | + name: "windows path", |
| 47 | + path: "C:\\ProgramData\\Foo\\Bar\\Qux.ovf", |
| 48 | + expected: "C:\\ProgramData\\Foo\\Bar\\Qux.mf", |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + imp := Importer{} |
| 53 | + |
| 54 | + for _, test := range manifestTests { |
| 55 | + if test.goos == runtime.GOOS { |
| 56 | + manifestPath := imp.manifestPath(test.path) |
| 57 | + if manifestPath != test.expected { |
| 58 | + t.Fatalf("'%s' failed: expected '%s', got '%s'", test.name, test.expected, manifestPath) |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments