TestConvertCPUSharesToCgroupV2Value tests the ConvertCPUSharesToCgroupV2Value function. Taken from https://github.com/opencontainers/cgroups/blob/v0.0.5/utils_test.go#L537-L564 (Apache License 2.0)
(t *testing.T)
| 79 | // Taken from https://github.com/opencontainers/cgroups/blob/v0.0.5/utils_test.go#L537-L564 |
| 80 | // (Apache License 2.0) |
| 81 | func TestConvertCPUSharesToCgroupV2Value(t *testing.T) { |
| 82 | const ( |
| 83 | sharesMin = 2 |
| 84 | sharesMax = 262144 |
| 85 | sharesDef = 1024 |
| 86 | weightMin = 1 |
| 87 | weightMax = 10000 |
| 88 | weightDef = 100 |
| 89 | unset = 0 |
| 90 | ) |
| 91 | cases := map[uint64]uint64{ |
| 92 | unset: unset, |
| 93 | |
| 94 | sharesMin - 1: weightMin, // Below the minimum (out of range). |
| 95 | sharesMin: weightMin, // Minimum. |
| 96 | sharesMin + 1: weightMin + 1, // Just above the minimum. |
| 97 | sharesDef: weightDef, // Default. |
| 98 | sharesMax - 1: weightMax, // Just below the maximum. |
| 99 | sharesMax: weightMax, // Maximum. |
| 100 | sharesMax + 1: weightMax, // Above the maximum (out of range). |
| 101 | } |
| 102 | for shares, want := range cases { |
| 103 | got := ConvertCPUSharesToCgroupV2Value(shares) |
| 104 | if got != want { |
| 105 | t.Errorf("ConvertCPUSharesToCgroupV2Value(%d): got %d, want %d", shares, got, want) |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func TestToResources(t *testing.T) { |
| 111 | var ( |
nothing calls this directly
no test coverage detected
searching dependent graphs…