-
Notifications
You must be signed in to change notification settings - Fork 46
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
base: main
Are you sure you want to change the base?
add UT for bypass #430
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
}, | ||
} | ||
|
||
patches2.ApplyFunc(isKmeshManaged, func(pod *corev1.Pod) bool { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golint mistake
pkg/controller/bypass/bypass_test.go
Outdated
}, | ||
} | ||
|
||
go StartByPassController(client) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if got := isKmeshManaged(tt.args.pod); got != tt.want { | |
assert.Equal(t, isKmeshManaged(tt.args.pod), tt.want) |
@@ -0,0 +1,287 @@ | |||
package bypass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright
There was a problem hiding this comment.
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]>
wantErr bool | ||
}{ | ||
{ | ||
name: "test1: pod with bypass label triggers enable bypass kmesh", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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", |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The descriptions are right?
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?: