github.com/blixtra/rkt@v0.8.1-0.20160204105720-ab0d1add1a43/stage1/init/kvm/resources_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/appc/spec/schema/types" 21 ) 22 23 func TestFindResources(t *testing.T) { 24 tests := []struct { 25 in types.Isolators 26 27 wmem int64 28 wcpu int64 29 }{ 30 { 31 types.Isolators{}, 32 33 defaultMem, 34 0, 35 }, 36 { 37 types.Isolators([]types.Isolator{ 38 newIsolator(` 39 { 40 "name": "resource/cpu", 41 "value": { 42 "limit": 100, 43 "request": 100 44 } 45 }`), 46 }), 47 48 defaultMem, 49 100, 50 }, 51 } 52 53 for i, tt := range tests { 54 gmem, gcpu := findResources(tt.in) 55 if gmem != tt.wmem { 56 t.Errorf("#%d: got mem=%d, want %d", i, gmem, tt.wmem) 57 } 58 if gcpu != tt.wcpu { 59 t.Errorf("#%d: got cpu=%d, want %d", i, gcpu, tt.wcpu) 60 } 61 } 62 } 63 64 func newIsolator(body string) (i types.Isolator) { 65 err := i.UnmarshalJSON([]byte(body)) 66 if err != nil { 67 panic(err) 68 } 69 return 70 }