Files
Yi ChenandGitHub 1b2df005e2 refactor: use ptr.To to replace util.XxxPtr (#2693)
* Use ptr.To instead of util.BoolPtr

Signed-off-by: Yi Chen <[email protected]>

* Use ptr.To[int32] instead of util.Int32Ptr

Signed-off-by: Yi Chen <[email protected]>

* Use ptr.To[int64] instead of util.Int64Ptr

Signed-off-by: Yi Chen <[email protected]>

* Use ptr.To instead of util.StringPtr

Signed-off-by: Yi Chen <[email protected]>

---------

Signed-off-by: Yi Chen <[email protected]>
2025-11-05 05:56:16 +00:00

57 lines
1.3 KiB
Go

/*
Copyright 2024 The Kubeflow authors.
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
https://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 resourceusage
import (
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/utils/ptr"
)
func TestCpuRequest(t *testing.T) {
testCases := []struct {
cores *int32
coreRequest *string
expected string
}{
{nil, nil, "1"},
{ptr.To[int32](1), nil, "1"},
{nil, ptr.To("1"), "1"},
{ptr.To[int32](1), ptr.To("500m"), "500m"},
}
for _, tc := range testCases {
actual, err := cpuRequest(tc.cores, tc.coreRequest)
assert.Nil(t, err)
assert.Equal(t, tc.expected, actual)
}
}
func TestCpuRequestInvalid(t *testing.T) {
invalidInputs := []string{
"",
"asd",
"Random 500m",
}
for _, input := range invalidInputs {
_, err := cpuRequest(nil, &input)
assert.NotNil(t, err)
}
}