github.com/demonoid81/containerd@v1.3.4/diff/apply/apply_linux_test.go (about) 1 // +build linux 2 3 /* 4 Copyright The containerd 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 apply 20 21 import ( 22 "testing" 23 ) 24 25 func TestGetOverlayPath(t *testing.T) { 26 good := []string{"upperdir=/test/upper", "lowerdir=/test/lower1:/test/lower2", "workdir=/test/work"} 27 path, parents, err := getOverlayPath(good) 28 if err != nil { 29 t.Fatalf("Get overlay path failed: %v", err) 30 } 31 if path != "/test/upper" { 32 t.Fatalf("Unexpected upperdir: %q", path) 33 } 34 if len(parents) != 2 || parents[0] != "/test/lower1" || parents[1] != "/test/lower2" { 35 t.Fatalf("Unexpected parents: %v", parents) 36 } 37 38 bad := []string{"lowerdir=/test/lower"} 39 _, _, err = getOverlayPath(bad) 40 if err == nil { 41 t.Fatalf("An error is expected") 42 } 43 } 44 45 func TestGetAufsPath(t *testing.T) { 46 for _, test := range []struct { 47 options []string 48 expectErr bool 49 }{ 50 { 51 options: []string{"random:option", "br:/test/rw=rw:/test/ro=ro+wh"}, 52 expectErr: false, 53 }, 54 { 55 options: []string{"random:option"}, 56 expectErr: true, 57 }, 58 { 59 options: []string{"br:/test/ro=ro+wh"}, 60 expectErr: true, 61 }, 62 } { 63 path, parents, err := getAufsPath(test.options) 64 if test.expectErr { 65 if err == nil { 66 t.Fatalf("An error is expected") 67 } 68 continue 69 } 70 if err != nil { 71 t.Fatalf("Get aufs path failed: %v", err) 72 } 73 if path != "/test/rw" { 74 t.Fatalf("Unexpected rw dir: %q", path) 75 } 76 if len(parents) != 1 || parents[0] != "/test/ro" { 77 t.Fatalf("Unexpected parents: %v", parents) 78 } 79 80 } 81 }