github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/tests/rkt_mount_overlay_test.go (about) 1 // Copyright 2017 The rkt Authors 2 // 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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build host coreos src kvm 16 17 package main 18 19 import ( 20 "os" 21 "path/filepath" 22 "syscall" 23 "testing" 24 25 "github.com/rkt/rkt/common" 26 "github.com/rkt/rkt/common/overlay" 27 ) 28 29 func overlayMount(cfg overlay.MountCfg) error { 30 // Create temporary directories with a configured prefix. 31 32 // Lower and Upper directories will create two text files 33 // to ensure the merging completed successfully. 34 cfg.Lower = mustTempDir(cfg.Lower) 35 createFileOrPanic(cfg.Lower, "1.txt") 36 37 cfg.Upper = mustTempDir(cfg.Upper) 38 createFileOrPanic(cfg.Upper, "2.txt") 39 40 cfg.Work = mustTempDir(cfg.Work) 41 cfg.Dest = mustTempDir(cfg.Dest) 42 43 // Ensure temporary directories will be removed after tests. 44 defer os.RemoveAll(cfg.Lower) 45 defer os.RemoveAll(cfg.Upper) 46 defer os.RemoveAll(cfg.Work) 47 defer os.RemoveAll(cfg.Dest) 48 49 err := overlay.Mount(&cfg) 50 if err != nil { 51 return err 52 } 53 54 // Unmount the destination directory when time comes. 55 defer syscall.Unmount(cfg.Dest, 0) 56 57 // Ensure both, 1.txt and 2.txt have been merged into the 58 // destination directory. 59 for _, ff := range []string{"1.txt", "2.txt"} { 60 _, err := os.Stat(filepath.Join(cfg.Dest, ff)) 61 if err != nil { 62 return err 63 } 64 } 65 66 return nil 67 } 68 69 func TestOverlayMount(t *testing.T) { 70 if err := common.SupportsOverlay(); err != nil { 71 t.Skipf("Overlay fs not supported: %v", err) 72 } 73 74 tests := []overlay.MountCfg{ 75 {"test1", "test2", "test3", "merged", ""}, 76 {"test:1", "test:2", "test:3", "merged:1", ""}, 77 {"test,1", "test,2", "test,3", "merged,1", ""}, 78 } 79 80 for i, tt := range tests { 81 err := overlayMount(tt) 82 if err != nil { 83 text := "#%d: expected to mount at %s, got error (err=%v)" 84 t.Errorf(text, i, tt.Dest, err) 85 } 86 } 87 }