-
Notifications
You must be signed in to change notification settings - Fork 350
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
feat: /quitquitquit api now responds to HTTP GET and POST requests. #1947
Changes from 1 commit
1e9736b
30f6a1d
0b53757
55a22c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1307,7 +1307,7 @@ func TestPProfServer(t *testing.T) { | |
} | ||
} | ||
|
||
func TestQuitQuitQuit(t *testing.T) { | ||
func TestQuitQuitQuitHttpPost(t *testing.T) { | ||
c := NewCommand(WithDialer(&spyDialer{})) | ||
c.SilenceUsage = true | ||
c.SilenceErrors = true | ||
|
@@ -1320,7 +1320,7 @@ func TestQuitQuitQuit(t *testing.T) { | |
err := c.ExecuteContext(ctx) | ||
errCh <- err | ||
}() | ||
resp, err := tryDial("GET", "http://localhost:9192/quitquitquit") | ||
resp, err := tryDial("HEAD", "http://localhost:9192/quitquitquit") | ||
if err != nil { | ||
t.Fatalf("failed to dial endpoint: %v", err) | ||
} | ||
|
@@ -1348,6 +1348,41 @@ func TestQuitQuitQuit(t *testing.T) { | |
} | ||
} | ||
|
||
func TestQuitQuitQuitHttpGet(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTTP There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
c := NewCommand(WithDialer(&spyDialer{})) | ||
c.SilenceUsage = true | ||
c.SilenceErrors = true | ||
c.SetArgs([]string{"--quitquitquit", "--admin-port", "9192", "my-project:my-region:my-instance"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use 9193 or some other port to avoid conflicts with the test above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
errCh := make(chan error) | ||
go func() { | ||
err := c.ExecuteContext(ctx) | ||
errCh <- err | ||
}() | ||
|
||
resp, err := tryDial("GET", "http://localhost:9192/quitquitquit") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we pull the port out as a constant to avoid this kind of mistake (9192 here, 9193 above) |
||
if err != nil { | ||
t.Fatalf("failed to dial endpoint: %v", err) | ||
} | ||
if resp.StatusCode != http.StatusOK { | ||
t.Fatalf("expected a 200 status, got = %v", resp.StatusCode) | ||
} | ||
|
||
var gotErr error | ||
select { | ||
case err := <-errCh: | ||
gotErr = err | ||
case <-time.After(30 * time.Second): | ||
t.Fatal("timeout waiting for error") | ||
} | ||
|
||
if !errors.Is(gotErr, errQuitQuitQuit) { | ||
t.Fatalf("want = %v, got = %v", errQuitQuitQuit, gotErr) | ||
} | ||
} | ||
|
||
type errorDialer struct { | ||
spyDialer | ||
} | ||
|
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.
HTTP
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.
Fixed.