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

scrape: refactor tests with t.Fatal #3299

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions scrape/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Test_AppRestrictionsEnabled(t *testing.T) {

got, err := client.AppRestrictionsEnabled("o")
if err != nil {
t.Errorf("AppRestrictionsEnabled returned err: %v", err)
t.Fatalf("AppRestrictionsEnabled returned err: %v", err)
}
if want := tt.want; got != want {
t.Errorf("AppRestrictionsEnabled returned %t, want %t", got, want)
Expand All @@ -55,7 +55,7 @@ func Test_ListOAuthApps(t *testing.T) {

got, err := client.ListOAuthApps("e")
if err != nil {
t.Errorf("ListOAuthApps(e) returned err: %v", err)
t.Fatalf("ListOAuthApps(e) returned err: %v", err)
}
want := []OAuthApp{
{
Expand Down
6 changes: 3 additions & 3 deletions scrape/forms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Test_ParseForms(t *testing.T) {
t.Run(tt.description, func(t *testing.T) {
node, err := html.Parse(strings.NewReader(tt.html))
if err != nil {
t.Errorf("error parsing html: %v", err)
t.Fatalf("error parsing html: %v", err)
}
if got, want := parseForms(node), tt.forms; !cmp.Equal(got, want) {
t.Errorf("parseForms(%q) returned %+v, want %+v", tt.html, got, want)
Expand All @@ -95,7 +95,7 @@ func Test_FetchAndSumbitForm(t *testing.T) {
mux.HandleFunc("/submit", func(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
t.Errorf("error parsing form: %v", err)
t.Fatalf("error parsing form: %v", err)
}
want := url.Values{"hidden": {"h"}, "name": {"n"}}
if got := r.Form; !cmp.Equal(got, want) {
Expand All @@ -107,7 +107,7 @@ func Test_FetchAndSumbitForm(t *testing.T) {
setValues := func(values url.Values) { values.Set("name", "n") }
_, err := fetchAndSubmitForm(client.Client, client.baseURL.String()+"/", setValues)
if err != nil {
t.Errorf("fetchAndSubmitForm returned err: %v", err)
t.Fatalf("fetchAndSubmitForm returned err: %v", err)
}
if !submitted {
t.Error("form was never submitted")
Expand Down
5 changes: 3 additions & 2 deletions scrape/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"
)

Expand All @@ -27,9 +28,9 @@ func setup(t *testing.T) (client *Client, mux *http.ServeMux) {

func copyTestFile(t *testing.T, w io.Writer, filename string) {
t.Helper()
f, err := os.Open("testdata/" + filename)
f, err := os.Open(filepath.Join("testdata", filename))
if err != nil {
t.Errorf("unable to open test file: %v", err)
t.Fatalf("unable to open test file: %v", err)
}
_, err = io.Copy(w, f)
if err != nil {
Expand Down
Loading