mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
79 lines
2.7 KiB
Go
79 lines
2.7 KiB
Go
/*
|
|
Copyright 2020 The Flux 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 canary
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
|
|
)
|
|
|
|
func TestDeploymentController_SyncStatus(t *testing.T) {
|
|
dc := deploymentConfigs{name: "podinfo", label: "name", labelValue: "podinfo"}
|
|
mocks := newDeploymentFixture(dc)
|
|
mocks.initializeCanary(t)
|
|
|
|
status := flaggerv1.CanaryStatus{
|
|
Phase: flaggerv1.CanaryPhaseProgressing,
|
|
FailedChecks: 2,
|
|
}
|
|
err := mocks.controller.SyncStatus(mocks.canary, status)
|
|
require.NoError(t, err)
|
|
|
|
res, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, status.Phase, res.Status.Phase)
|
|
assert.Equal(t, status.FailedChecks, res.Status.FailedChecks)
|
|
|
|
require.NotNil(t, res.Status.TrackedConfigs)
|
|
configs := *res.Status.TrackedConfigs
|
|
secret := newDeploymentControllerTestSecret()
|
|
_, exists := configs["secret/"+secret.GetName()]
|
|
assert.True(t, exists, "Secret %s not found in status", secret.GetName())
|
|
}
|
|
|
|
func TestDeploymentController_SetFailedChecks(t *testing.T) {
|
|
dc := deploymentConfigs{name: "podinfo", label: "name", labelValue: "podinfo"}
|
|
mocks := newDeploymentFixture(dc)
|
|
mocks.initializeCanary(t)
|
|
|
|
err := mocks.controller.SetStatusFailedChecks(mocks.canary, 1)
|
|
require.NoError(t, err)
|
|
|
|
res, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 1, res.Status.FailedChecks)
|
|
}
|
|
|
|
func TestDeploymentController_SetState(t *testing.T) {
|
|
dc := deploymentConfigs{name: "podinfo", label: "name", labelValue: "podinfo"}
|
|
mocks := newDeploymentFixture(dc)
|
|
mocks.initializeCanary(t)
|
|
|
|
err := mocks.controller.SetStatusPhase(mocks.canary, flaggerv1.CanaryPhaseProgressing)
|
|
require.NoError(t, err)
|
|
|
|
res, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, flaggerv1.CanaryPhaseProgressing, res.Status.Phase)
|
|
}
|