Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/contributors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ users:
rishi-jat:
name: Rishi Jat
email: rishijat098@gmail.com
parthdagia05:
name: Parth Dagia
email: parth.24bcs10414@sst.scaler.com
73 changes: 73 additions & 0 deletions pkg/unikontainers/hypervisors/utils_test.go
Original file line number Diff line number Diff line change
@@ -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))
})
}
}
Loading