github.com/minio/console@v1.4.1/web-app/src/common/__tests__/utils.test.ts (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 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 { 18 erasureCodeCalc, 19 getBytes, 20 niceBytes, 21 setMemoryResource, 22 } from "../utils"; 23 24 test("A variety of formatting results", () => { 25 expect(niceBytes("1024")).toBe("1.0 KiB"); 26 expect(niceBytes("1048576")).toBe("1.0 MiB"); 27 expect(niceBytes("1073741824")).toBe("1.0 GiB"); 28 }); 29 30 test("From value and unit to a number of bytes", () => { 31 expect(getBytes("1", "KiB")).toBe("1024"); 32 expect(getBytes("1", "MiB")).toBe("1048576"); 33 expect(getBytes("1", "GiB")).toBe("1073741824"); 34 }); 35 36 test("From value and unit to a number of bytes for kubernetes", () => { 37 expect(getBytes("1", "Ki", true)).toBe("1024"); 38 expect(getBytes("1", "Mi", true)).toBe("1048576"); 39 expect(getBytes("1", "Gi", true)).toBe("1073741824"); 40 expect(getBytes("7500", "Gi", true)).toBe("8053063680000"); 41 }); 42 43 test("Determine the amount of memory to use", () => { 44 expect(setMemoryResource(1024, "1024", 1024)).toStrictEqual({ 45 error: "There are not enough memory resources available", 46 limit: 0, 47 request: 0, 48 }); 49 expect(setMemoryResource(64, "1099511627776", 34359738368)).toStrictEqual({ 50 error: 51 "The requested memory is greater than the max available memory for the selected number of nodes", 52 limit: 0, 53 request: 0, 54 }); 55 expect(setMemoryResource(2, "17179869184", 34359738368)).toStrictEqual({ 56 error: "", 57 limit: 34359738368, 58 request: 2147483648, 59 }); 60 }); 61 62 test("Determine the correct values for EC Parity calculation", () => { 63 expect(erasureCodeCalc([], 50, 5000, 4)).toStrictEqual({ 64 error: 1, 65 defaultEC: "", 66 erasureCodeSet: 0, 67 maxEC: "", 68 rawCapacity: "0", 69 storageFactors: [], 70 }); 71 expect(erasureCodeCalc(["EC:2"], 4, 26843545600, 4)).toStrictEqual({ 72 error: 0, 73 storageFactors: [ 74 { 75 erasureCode: "EC:2", 76 storageFactor: 2, 77 maxCapacity: "53687091200", 78 maxFailureTolerations: 2, 79 }, 80 ], 81 maxEC: "EC:2", 82 rawCapacity: "107374182400", 83 erasureCodeSet: 4, 84 defaultEC: "EC:2", 85 }); 86 });