github.com/moby/docker@v26.1.3+incompatible/runconfig/hostconfig_test.go (about) 1 //go:build !windows 2 3 package runconfig // import "github.com/docker/docker/runconfig" 4 5 import ( 6 "testing" 7 8 "github.com/docker/docker/api/types/container" 9 "github.com/docker/docker/pkg/sysinfo" 10 ) 11 12 func TestValidateResources(t *testing.T) { 13 type resourceTest struct { 14 ConfigCPURealtimePeriod int64 15 ConfigCPURealtimeRuntime int64 16 SysInfoCPURealtime bool 17 ErrorExpected bool 18 FailureMsg string 19 } 20 21 tests := []resourceTest{ 22 { 23 ConfigCPURealtimePeriod: 1000, 24 ConfigCPURealtimeRuntime: 1000, 25 SysInfoCPURealtime: true, 26 ErrorExpected: false, 27 FailureMsg: "Expected valid configuration", 28 }, 29 { 30 ConfigCPURealtimePeriod: 5000, 31 ConfigCPURealtimeRuntime: 5000, 32 SysInfoCPURealtime: false, 33 ErrorExpected: true, 34 FailureMsg: "Expected failure when cpu-rt-period is set but kernel doesn't support it", 35 }, 36 { 37 ConfigCPURealtimePeriod: 5000, 38 ConfigCPURealtimeRuntime: 5000, 39 SysInfoCPURealtime: false, 40 ErrorExpected: true, 41 FailureMsg: "Expected failure when cpu-rt-runtime is set but kernel doesn't support it", 42 }, 43 { 44 ConfigCPURealtimePeriod: 5000, 45 ConfigCPURealtimeRuntime: 10000, 46 SysInfoCPURealtime: true, 47 ErrorExpected: true, 48 FailureMsg: "Expected failure when cpu-rt-runtime is greater than cpu-rt-period", 49 }, 50 } 51 52 for _, rt := range tests { 53 var hc container.HostConfig 54 hc.Resources.CPURealtimePeriod = rt.ConfigCPURealtimePeriod 55 hc.Resources.CPURealtimeRuntime = rt.ConfigCPURealtimeRuntime 56 57 var si sysinfo.SysInfo 58 si.CPURealtime = rt.SysInfoCPURealtime 59 60 if err := validateResources(&hc, &si); (err != nil) != rt.ErrorExpected { 61 t.Fatal(rt.FailureMsg, err) 62 } 63 } 64 }