|
| 1 | +// This file is part of MinIO Console Server |
| 2 | +// Copyright (c) 2020 MinIO, Inc. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +import { getBytes, niceBytes, setMemoryResource } from "../utils"; |
| 18 | + |
| 19 | +test("A variety of formatting results", () => { |
| 20 | + expect(niceBytes("1024")).toBe("1.0 KiB"); |
| 21 | + expect(niceBytes("1048576")).toBe("1.0 MiB"); |
| 22 | + expect(niceBytes("1073741824")).toBe("1.0 GiB"); |
| 23 | +}); |
| 24 | + |
| 25 | +test("From value and unit to a number of bytes", () => { |
| 26 | + expect(getBytes("1", "KiB")).toBe("1024"); |
| 27 | + expect(getBytes("1", "MiB")).toBe("1048576"); |
| 28 | + expect(getBytes("1", "GiB")).toBe("1073741824"); |
| 29 | +}); |
| 30 | + |
| 31 | +test("From value and unit to a number of bytes for kubernetes", () => { |
| 32 | + expect(getBytes("1", "Ki", true)).toBe("1024"); |
| 33 | + expect(getBytes("1", "Mi", true)).toBe("1048576"); |
| 34 | + expect(getBytes("1", "Gi", true)).toBe("1073741824"); |
| 35 | +}); |
| 36 | + |
| 37 | +test("Determine the amount of memory to use", () => { |
| 38 | + expect(setMemoryResource(1024, "1024", 1024)).toStrictEqual({ |
| 39 | + error: "There are not enough memory resources available", |
| 40 | + limit: 0, |
| 41 | + request: 0, |
| 42 | + }); |
| 43 | + expect(setMemoryResource(64, "1099511627776", 34359738368)).toStrictEqual({ |
| 44 | + error: |
| 45 | + "The requested memory is greater than the max available memory for the selected number of nodes", |
| 46 | + limit: 0, |
| 47 | + request: 0, |
| 48 | + }); |
| 49 | + expect(setMemoryResource(2, "17179869184", 34359738368)).toStrictEqual({ |
| 50 | + error: "", |
| 51 | + limit: 34359738368, |
| 52 | + request: 2147483648, |
| 53 | + }); |
| 54 | +}); |
0 commit comments