OpaqueIntResourceName unit tests

This commit is contained in:
clairew 2017-07-27 01:06:34 -07:00 committed by clairew
parent acf7b5715c
commit aeb3b761b2

View File

@ -17,6 +17,7 @@ limitations under the License.
package helper
import (
"fmt"
"reflect"
"testing"
@ -26,6 +27,64 @@ import (
"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) {
testCases := []struct {
existing []v1.NodeAddress