123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- /*
- Copyright 2022.
- 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 controllers
- import (
- "testing"
- appv1 "github.com/kakao/bluegreen/api/v1"
- v1 "github.com/kakao/bluegreen/api/v1"
- "github.com/stretchr/testify/assert"
- corev1 "k8s.io/api/core/v1"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "k8s.io/apimachinery/pkg/runtime"
- utilruntime "k8s.io/apimachinery/pkg/util/runtime"
- clientgoscheme "k8s.io/client-go/kubernetes/scheme"
- "sigs.k8s.io/controller-runtime/pkg/client/fake"
- )
- var (
- testScheme = runtime.NewScheme()
- )
- func init() {
- utilruntime.Must(clientgoscheme.AddToScheme(testScheme))
- utilruntime.Must(appv1.AddToScheme(testScheme))
- }
- func TestBlueGreenReconciler_mutateBlueGreenService(t *testing.T) {
- t.Run("Should add proper labels and OwnerReferences", func(t *testing.T) {
- r := &BlueGreenReconciler{
- Client: fake.NewClientBuilder().WithScheme(testScheme).WithRuntimeObjects().Build(),
- Scheme: testScheme,
- }
- const Name = "bluegreen-test"
- const Namespace = "test"
- svc := &corev1.Service{ObjectMeta: metav1.ObjectMeta{Namespace: Namespace, Name: Name}}
- err := r.mutateBlueGreenService(
- &v1.BlueGreen{ObjectMeta: metav1.ObjectMeta{Namespace: Namespace, Name: Name, UID: "0000-0000"}},
- svc, "test", appv1.Blue)()
- assert.NoError(t, err)
- assert.Equal(t, 1, len(svc.ObjectMeta.OwnerReferences))
- assert.Equal(t, "app.demo.kakao.com", svc.Spec.Selector["app.kubernetes.io/managed-by"])
- assert.Equal(t, "Blue", svc.Spec.Selector["app.kubernetes.io/phase"])
- assert.Equal(t, "test", svc.Spec.Selector["app.kubernetes.io/name"])
- /* more validation here */
- })
- }
|