github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/filesystem/filesystem_test.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 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 package filesystem 16 17 import ( 18 "testing" 19 20 "github.com/alibaba/sealer/pkg/runtime" 21 22 v2 "github.com/alibaba/sealer/types/api/v2" 23 24 k8sV1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 26 v1 "github.com/alibaba/sealer/types/api/v1" 27 ) 28 29 var testCluster = &v2.Cluster{ 30 ObjectMeta: k8sV1.ObjectMeta{Name: "my-cluster"}, 31 Spec: v2.ClusterSpec{ 32 Image: "kubernetes:v1.19.9", 33 Hosts: []v2.Host{ 34 { 35 IPS: []string{ 36 "192.168.56.111", 37 }, 38 Roles: []string{"master"}, 39 }, { 40 IPS: []string{ 41 "192.168.56.112", 42 }, 43 Roles: []string{"node"}, 44 }, 45 }, 46 SSH: v1.SSH{ 47 User: "root", 48 Passwd: "******", 49 }, 50 }, 51 } 52 53 func TestMount(t *testing.T) { 54 type args struct { 55 cluster *v2.Cluster 56 } 57 tests := []struct { 58 name string 59 arg args 60 wantErr bool 61 }{ 62 { 63 name: "test mount", 64 arg: args{ 65 cluster: testCluster, 66 }, 67 wantErr: false, 68 }, 69 } 70 rootfs := "/var/lib/sealer/data/overlay2/" 71 for _, tt := range tests { 72 t.Run(tt.name, func(t *testing.T) { 73 fileSystem, err := NewFilesystem(rootfs) 74 if err != nil { 75 t.Errorf("%s failed: %v", tt.name, err) 76 } 77 78 if err = fileSystem.MountRootfs(tt.arg.cluster, append(runtime.GetMasterIPList(testCluster), runtime.GetNodeIPList(testCluster)...), true); err != nil { 79 t.Errorf("%s failed: %v", tt.name, err) 80 } 81 }) 82 } 83 } 84 85 func TestUnMount(t *testing.T) { 86 type args struct { 87 cluster *v2.Cluster 88 } 89 tests := []struct { 90 name string 91 arg args 92 wantErr bool 93 }{ 94 { 95 name: "test unmount", 96 arg: args{ 97 cluster: testCluster, 98 }, 99 wantErr: false, 100 }, 101 } 102 rootfs := "/var/lib/sealer/data/overlay2/" 103 for _, tt := range tests { 104 t.Run(tt.name, func(t *testing.T) { 105 fileSystem, err := NewFilesystem(rootfs) 106 if err != nil { 107 t.Errorf("%s failed: %v", tt.name, err) 108 } 109 if err = fileSystem.UnMountRootfs(tt.arg.cluster, append(tt.arg.cluster.GetMasterIPList(), tt.arg.cluster.GetNodeIPList()...)); err != nil { 110 t.Errorf("%s failed: %v", tt.name, err) 111 } 112 }) 113 } 114 }