2017-08-15 22:45:31 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 The Kubernetes 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
|
|
|
|
|
|
|
|
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 gce
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2018-02-20 21:02:02 +00:00
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
|
2017-08-15 22:45:31 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServiceNetworkTierAnnotationKey(t *testing.T) {
|
|
|
|
createTestService := func() *v1.Service {
|
|
|
|
return &v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
UID: "randome-uid",
|
|
|
|
Name: "test-svc",
|
|
|
|
Namespace: "test-ns",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for testName, testCase := range map[string]struct {
|
|
|
|
annotations map[string]string
|
2018-02-20 21:02:02 +00:00
|
|
|
expectedTier cloud.NetworkTier
|
2017-08-15 22:45:31 +00:00
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
"Use the default when the annotation does not exist": {
|
|
|
|
annotations: nil,
|
2018-02-20 21:02:02 +00:00
|
|
|
expectedTier: cloud.NetworkTierDefault,
|
2017-08-15 22:45:31 +00:00
|
|
|
},
|
|
|
|
"Standard tier": {
|
|
|
|
annotations: map[string]string{NetworkTierAnnotationKey: "Standard"},
|
2018-02-20 21:02:02 +00:00
|
|
|
expectedTier: cloud.NetworkTierStandard,
|
2017-08-15 22:45:31 +00:00
|
|
|
},
|
|
|
|
"Premium tier": {
|
|
|
|
annotations: map[string]string{NetworkTierAnnotationKey: "Premium"},
|
2018-02-20 21:02:02 +00:00
|
|
|
expectedTier: cloud.NetworkTierPremium,
|
2017-08-15 22:45:31 +00:00
|
|
|
},
|
|
|
|
"Report an error on invalid network tier value": {
|
|
|
|
annotations: map[string]string{NetworkTierAnnotationKey: "Unknown-tier"},
|
2018-02-20 21:02:02 +00:00
|
|
|
expectedTier: cloud.NetworkTierPremium,
|
2017-08-15 22:45:31 +00:00
|
|
|
expectErr: true,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(testName, func(t *testing.T) {
|
|
|
|
svc := createTestService()
|
|
|
|
svc.Annotations = testCase.annotations
|
|
|
|
actualTier, err := GetServiceNetworkTier(svc)
|
|
|
|
assert.Equal(t, testCase.expectedTier, actualTier)
|
|
|
|
assert.Equal(t, testCase.expectErr, err != nil)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|