-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 support for body_path
in HTTP probe config.
#392
Changes from 4 commits
8375421
cf2bc45
427d68b
c97981f
b72856c
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 |
---|---|---|
|
@@ -164,6 +164,33 @@ func TestPost(t *testing.T) { | |
} | ||
} | ||
|
||
func TestPostBody(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "POST" { | ||
w.WriteHeader(http.StatusBadRequest) | ||
} | ||
})) | ||
defer ts.Close() | ||
|
||
recorder := httptest.NewRecorder() | ||
registry := prometheus.NewRegistry() | ||
testCTX, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
result := ProbeHTTP(testCTX, ts.URL, | ||
config.Module{ | ||
Timeout: time.Second, | ||
HTTP: config.HTTPProbe{ | ||
IPProtocolFallback: true, | ||
Method: "POST", | ||
BodyFile: "./http.go", | ||
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. You can create a testdata directory, and a file with known contents there - plus verify that's what's coming through. 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. You should still change this to use explicit testdata files, rather than the source itself |
||
}, | ||
}, registry, log.NewNopLogger()) | ||
body := recorder.Body.String() | ||
if !result { | ||
t.Fatalf("Post test failed unexpectedly, got %s", body) | ||
} | ||
} | ||
|
||
func TestBasicAuth(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
})) | ||
|
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.
Make sure this gets closed