gitee.com/mysnapcore/mysnapd@v0.1.0/snap/quota/export_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2021 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package quota 21 22 import ( 23 "gitee.com/mysnapcore/mysnapd/testutil" 24 ) 25 26 type GroupQuotaAllocations = groupQuotaAllocations 27 28 func (grp *Group) GetCPUQuotaPercentage() int { 29 return grp.getCurrentCPUAllocation() 30 } 31 32 func (grp *Group) SetInternalSubGroups(grps []*Group) { 33 grp.subGroups = grps 34 } 35 36 func (grp *Group) QuotaUpdateCheck(resourceLimits Resources) error { 37 return grp.validateQuotasFit(resourceLimits) 38 } 39 40 func (grp *Group) ValidateGroup() error { 41 return grp.validate() 42 } 43 44 func (grp *Group) InspectInternalQuotaAllocations() map[string]*GroupQuotaAllocations { 45 allQuotas := make(map[string]*GroupQuotaAllocations) 46 grp.getQuotaAllocations(allQuotas) 47 return allQuotas 48 } 49 50 func ResourcesClone(r *Resources) Resources { 51 return r.clone() 52 } 53 54 func MockCgroupVer(mockVer int) (restore func()) { 55 r := testutil.Backup(&cgroupVer) 56 cgroupVer = mockVer 57 return r 58 } 59 60 func MockCgroupVerErr(mockErr error) (restore func()) { 61 r := testutil.Backup(&cgroupVerErr) 62 cgroupVerErr = mockErr 63 return r 64 } 65 66 func MockRuntimeNumCPU(mock func() int) (restore func()) { 67 r := testutil.Backup(&runtimeNumCPU) 68 runtimeNumCPU = mock 69 return r 70 }