github.com/stackdocker/rkt@v0.10.1-0.20151109095037-1aa827478248/stage1/init/kvm/mount_test.go (about) 1 // Copyright 2015 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 package kvm 16 17 import ( 18 "testing" 19 20 "github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types" 21 ) 22 23 func TestVolumesToKvmDiskArgs(t *testing.T) { 24 tests := []struct { 25 volumes []types.Volume 26 expected []string 27 }{ 28 { // one host volume - one argument 29 volumes: []types.Volume{{Name: types.ACName("foo"), Kind: "host", Source: "src1"}}, 30 expected: []string{"--9p=src1,foo"}, 31 }, 32 { // on empty volume - no arguments 33 volumes: []types.Volume{{Name: types.ACName("foo"), Kind: "empty", Source: "src1"}}, 34 expected: []string{}, 35 }, 36 { // two host volumes 37 volumes: []types.Volume{ 38 {Name: types.ACName("foo"), Kind: "host", Source: "src1"}, 39 {Name: types.ACName("bar"), Kind: "host", Source: "src2"}, 40 }, 41 expected: []string{"--9p=src1,foo", "--9p=src2,bar"}, 42 }, 43 { // mix host and empty 44 volumes: []types.Volume{ 45 {Name: types.ACName("foo"), Kind: "host", Source: "src1"}, 46 {Name: types.ACName("baz"), Kind: "empty", Source: "src1"}, 47 {Name: types.ACName("bar"), Kind: "host", Source: "src2"}, 48 }, 49 expected: []string{"--9p=src1,foo", "--9p=src2,bar"}, 50 }, 51 } 52 53 for i, tt := range tests { 54 got := VolumesToKvmDiskArgs(tt.volumes) 55 if len(got) != len(tt.expected) { 56 t.Errorf("#%d: expected %v elements got %v", i, len(tt.expected), len(got)) 57 } else { 58 for iarg, argExpected := range tt.expected { 59 if got[iarg] != argExpected { 60 t.Errorf("#%d: arg %d expected `%v` got `%v`", i, iarg, argExpected, got[iarg]) 61 } 62 } 63 } 64 } 65 }