mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
44 lines
998 B
Go
44 lines
998 B
Go
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License-AGPL.txt in the project root for license information.
|
|
|
|
package v2
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMax(t *testing.T) {
|
|
mountPoint := createMaxFile(t)
|
|
|
|
cpu := NewCpuControllerWithMount(mountPoint, "cgroup")
|
|
quota, period, err := cpu.Max()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
assert.Equal(t, uint64(200_000), quota)
|
|
assert.Equal(t, uint64(100_000), period)
|
|
}
|
|
|
|
func createMaxFile(t *testing.T) string {
|
|
mountPoint, err := os.MkdirTemp("", "test.max")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cgroupPath := filepath.Join(mountPoint, "cgroup")
|
|
if err := os.MkdirAll(cgroupPath, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := os.WriteFile(filepath.Join(cgroupPath, "cpu.max"), []byte("200000 100000\n"), 0755); err != nil {
|
|
t.Fatalf("failed to create cpu.max file: %v", err)
|
|
}
|
|
|
|
return mountPoint
|
|
}
|