Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add UT for bypass #430

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

add UT for bypass #430

wants to merge 1 commit into from

Conversation

weli-l
Copy link
Contributor

@weli-l weli-l commented Jun 12, 2024

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #371

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign supercharge-xsy for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

},
}

patches2.ApplyFunc(isKmeshManaged, func(pod *corev1.Pod) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit we donot need to replace isKmeshManaged, which is simple checking pod annotations

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.beforeFunc()
time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

donot use sleep, it is very time costy. use async notify instead

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.beforeFunc()
time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, prevent using sleep

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
"kmesh.net/kmesh/pkg/utils"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golint mistake

},
}

go StartByPassController(client)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a goroutine on this side. Is it possible that the use a goroutine on this side results in a 1s interval between tests?

}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isKmeshManaged(tt.args.pod); got != tt.want {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if got := isKmeshManaged(tt.args.pod); got != tt.want {
assert.Equal(t, isKmeshManaged(tt.args.pod), tt.want)

@@ -0,0 +1,287 @@
package bypass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add copyright

Signed-off-by: weli-l <[email protected]>
@hzxuzhonghu hzxuzhonghu changed the title add UT add UT for bypass Jun 14, 2024
wantErr bool
}{
{
name: "test1: pod with bypass label triggers enable bypass kmesh",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to add a prefix like "test1"

want bool
}{
{
name: "test1: annotation with kmesh.net/redirection=enabled, should return true",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

want bool
}{
{
name: "test1: pod withsidecar inject annotation, should return true",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "test1: pod withsidecar inject annotation, should return true",
name: "test1: pod with sidecar inject annotation, should return true",

wantErr bool
}{
{
name: "test1: pod with sidecar annotation triggers addIptables",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

beforeFunc: func() {
count = 0
err := client.CoreV1().Pods("default").Delete(context.TODO(), "test-pod-with-label", metav1.DeleteOptions{})
require.NoError(t, err, "failed to create test pod")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
require.NoError(t, err, "failed to create test pod")
require.NoError(t, err, "failed to delete test pod")

},
afterFunc: func() {
assert.Equal(t, 1, addFuncCallCount, "AddFunc should not been called")
assert.Equal(t, 0, delFuncCallCount, "DelFunc should have been called once")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descriptions are right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add UT for Bypass
5 participants