From bb765707d40b4693fedb52b7f30a0f9c12392e85 Mon Sep 17 00:00:00 2001 From: Parth Dagia Date: Thu, 14 May 2026 15:10:33 +0530 Subject: [PATCH 1/2] test(hypervisors): add unit tests for bytesToMiB and bytesToMB Adds table-driven tests for the two byte-conversion helpers in pkg/unikontainers/hypervisors/utils.go, using testify/assert. Each helper is covered for zero, sub-unit, exact-unit, multiple, and large-value inputs. Signed-off-by: Parth Dagia --- pkg/unikontainers/hypervisors/utils_test.go | 73 +++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 pkg/unikontainers/hypervisors/utils_test.go diff --git a/pkg/unikontainers/hypervisors/utils_test.go b/pkg/unikontainers/hypervisors/utils_test.go new file mode 100644 index 00000000..ab4f7373 --- /dev/null +++ b/pkg/unikontainers/hypervisors/utils_test.go @@ -0,0 +1,73 @@ +// Copyright (c) 2023-2026, Nubificus LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package hypervisors + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBytesToMiB(t *testing.T) { + t.Parallel() + + const mib uint64 = 1024 * 1024 + + cases := []struct { + name string + input uint64 + expected uint64 + }{ + {"zero", 0, 0}, + {"less than one MiB truncates to zero", mib - 1, 0}, + {"exactly one MiB", mib, 1}, + {"exactly two MiB", 2 * mib, 2}, + {"non-multiple truncates down", mib + (mib / 2), 1}, + {"large value", 1024 * mib, 1024}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + assert.Equal(t, tc.expected, bytesToMiB(tc.input)) + }) + } +} + +func TestBytesToMB(t *testing.T) { + t.Parallel() + + const mb uint64 = 1000 * 1000 + + cases := []struct { + name string + input uint64 + expected uint64 + }{ + {"zero", 0, 0}, + {"less than one MB truncates to zero", mb - 1, 0}, + {"exactly one MB", mb, 1}, + {"exactly two MB", 2 * mb, 2}, + {"non-multiple truncates down", mb + (mb / 2), 1}, + {"large value", 1024 * mb, 1024}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + assert.Equal(t, tc.expected, bytesToMB(tc.input)) + }) + } +} From 04c6f6d0998ef509b7e63a454800afa08dbd3ed0 Mon Sep 17 00:00:00 2001 From: Parth Dagia Date: Thu, 14 May 2026 15:10:35 +0530 Subject: [PATCH 2/2] chore: add contributor entry Signed-off-by: Parth Dagia --- .github/contributors.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/contributors.yaml b/.github/contributors.yaml index d8f4a6b2..277329a1 100644 --- a/.github/contributors.yaml +++ b/.github/contributors.yaml @@ -95,3 +95,6 @@ users: rishi-jat: name: Rishi Jat email: rishijat098@gmail.com + parthdagia05: + name: Parth Dagia + email: parth.24bcs10414@sst.scaler.com