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

[YUNIKORN-2650]Complete or remove web_server_test#TestProxy #853

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pkg/webtest/web_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,43 @@ func TestWebServer(t *testing.T) {
}

func TestProxy(t *testing.T) {
mux := http.NewServeMux()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test case is duplicate to TestWebServer, so I prefer to remove TestProxy instead of having many duplicate code. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I think we can remove TestProxy. No problem, I'll make this change.

mux.HandleFunc("/ws/v1/test", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "PROXY OK")
})
proxiedServer := http.Server{
Addr: ":40003",
Handler: mux,
ReadHeaderTimeout: 10 * time.Second,
}
go func() {
if err := proxiedServer.ListenAndServe(); err != nil {
if !errors.Is(err, http.ErrServerClosed) {
assert.NilError(t, err, "failed to start proxied server")
}
}
}()
defer func() {
if err := proxiedServer.Close(); err != nil {
if !errors.Is(err, http.ErrServerClosed) {
assert.NilError(t, err, "failed to stop proxied server")
}
}
}()

time.Sleep(100 * time.Millisecond)

server, err := NewWebServer("testdata", "127.0.0.1:40004", "http://127.0.0.1:40003")
assert.NilError(t, err, "failed to create main server")
server.Start()
defer server.Stop()

time.Sleep(100 * time.Millisecond)

res, err := http.Get("http://127.0.0.1:40004/ws/v1/test")
assert.NilError(t, err, "failed to read from main server")
body, err := io.ReadAll(res.Body)
assert.NilError(t, err, "failed to read body")
str := string(body)
assert.Check(t, strings.Contains(str, "PROXY OK"), "proxy test string not found")
}
Loading