Skip to content

Commit

Permalink
E2E test
Browse files Browse the repository at this point in the history
Signed-off-by: lubronzhan <lubronzhan@gmail.com>
  • Loading branch information
lubronzhan committed Feb 18, 2024
1 parent e6f1b03 commit 78cd355
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions test/e2e/filewatcher/filewatcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright Project Contour 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.

//go:build e2e

package filewatcher

import (
"context"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
apps_v1 "k8s.io/api/apps/v1"
core_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/projectcontour/contour/test/e2e"
)

var f = e2e.NewFramework(true)

func TestFileWatcher(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "File Watcher tests")
}

var _ = BeforeSuite(func() {
// just need 1 contour pod
f.Deployment.ContourDeployment.Spec.Replicas = ptr.To(int32(1))
require.NoError(f.T(), f.Deployment.EnsureResourcesForInclusterContour(true))
})

var _ = Describe("Contour file watcher", func() {
Context("Update configMap of contour", func() {
Specify("Contour should restart after configMap is restarted", func() {
By("Get Contour pod's restart time")
cd := &apps_v1.Deployment{
ObjectMeta: meta_v1.ObjectMeta{
Name: f.Deployment.ContourDeployment.Name,
Namespace: f.Deployment.ContourDeployment.Namespace,
},
}
require.NoError(f.T(), f.Client.Get(context.TODO(), client.ObjectKeyFromObject(cd), cd))

labelSelector := cd.Spec.Selector
require.Equal(f.T(), len(labelSelector.MatchLabels), 1)

Check failure on line 61 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)

Check failure on line 61 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)

var podList core_v1.PodList
require.NoError(f.T(), f.Client.List(context.TODO(), &podList, client.MatchingLabels(labelSelector.MatchLabels)))
require.NotNil(f.T(), podList)
require.Equal(f.T(), len(podList.Items), 1)

Check failure on line 66 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)

Check failure on line 66 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)
require.Equal(f.T(), len(podList.Items[0].Status.ContainerStatuses), 1)

Check failure on line 67 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)

Check failure on line 67 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)

previousRestartCount := podList.Items[0].Status.ContainerStatuses[0].RestartCount

By("Get ConfigMap")
cm := &core_v1.ConfigMap{
ObjectMeta: meta_v1.ObjectMeta{
Name: f.Deployment.ContourConfigMap.Name,
Namespace: f.Deployment.ContourConfigMap.Namespace,
},
}
require.NoError(f.T(), f.Client.Get(context.TODO(), client.ObjectKeyFromObject(cm), cm))

By("Update configmap's content")
newConfigMapContent := `
accesslog-format: envoy`
cm.Data["contour.yaml"] = newConfigMapContent

require.NoError(f.T(), f.Client.Update(context.TODO(), cm))

By("Contour pod's restartCount should get larger")
require.Eventually(f.T(), func() bool {
var podList core_v1.PodList
require.NoError(f.T(), f.Client.List(context.TODO(), &podList, client.MatchingLabels(labelSelector.MatchLabels)))
require.NotNil(f.T(), podList)
require.Equal(f.T(), len(podList.Items), 1)

Check failure on line 92 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)

Check failure on line 92 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)
require.Equal(f.T(), len(podList.Items[0].Status.ContainerStatuses), 1)

Check failure on line 93 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)

Check failure on line 93 in test/e2e/filewatcher/filewatcher_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use require.Len (testifylint)
return podList.Items[0].Status.ContainerStatuses[0].RestartCount > previousRestartCount
}, time.Minute*2, time.Second)
})
})
})

var _ = AfterSuite(func() {
require.NoError(f.T(), f.Deployment.DeleteResourcesForInclusterContour())
})

0 comments on commit 78cd355

Please sign in to comment.