mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
OpaqueIntResourceName unit tests
This commit is contained in:
parent
acf7b5715c
commit
aeb3b761b2
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -26,6 +27,64 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestIsOpaqueIntResourceName(t *testing.T) { // resourceName input with the correct OpaqueIntResourceName prefix ("pod.alpha.kubernetes.io/opaque-int-resource-") should pass
|
||||||
|
testCases := []struct {
|
||||||
|
resourceName v1.ResourceName
|
||||||
|
expectVal bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
resourceName: "pod.alpha.kubernetes.io/opaque-int-resource-foo",
|
||||||
|
expectVal: true, // resourceName should pass because the resourceName has the correct prefix.
|
||||||
|
},
|
||||||
|
{
|
||||||
|
resourceName: "foo",
|
||||||
|
expectVal: false, // resourceName should fail because the resourceName has the wrong prefix.
|
||||||
|
},
|
||||||
|
{
|
||||||
|
resourceName: "",
|
||||||
|
expectVal: false, // resourceName should fail, empty resourceName.
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
t.Run(fmt.Sprintf("resourceName input=%s, expected value=%v", tc.resourceName, tc.expectVal), func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
v := IsOpaqueIntResourceName(tc.resourceName)
|
||||||
|
if v != tc.expectVal {
|
||||||
|
t.Errorf("Got %v but expected %v", v, tc.expectVal)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOpaqueIntResourceName(t *testing.T) { // each output should have the correct appended prefix ("pod.alpha.kubernetes.io/opaque-int-resource-") for opaque counted resources.
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
expectVal v1.ResourceName
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "foo",
|
||||||
|
expectVal: "pod.alpha.kubernetes.io/opaque-int-resource-foo", // append prefix to input string foo
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
expectVal: "pod.alpha.kubernetes.io/opaque-int-resource-", // append prefix to input empty string
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
t.Run(fmt.Sprintf("name input=%s, expected value=%s", tc.name, tc.expectVal), func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
v := OpaqueIntResourceName(tc.name)
|
||||||
|
if v != tc.expectVal {
|
||||||
|
t.Errorf("Got %v but expected %v", v, tc.expectVal)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddToNodeAddresses(t *testing.T) {
|
func TestAddToNodeAddresses(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
existing []v1.NodeAddress
|
existing []v1.NodeAddress
|
||||||
|
Loading…
Reference in New Issue
Block a user