Skip to content

Commit 5d48fa5

Browse files
cagedmantisgopherbot
authored andcommitted
internal/gomote: fix flaky TestWriteFileFromURL test
This change fixes a flaky test introduced in CL 397596. The test was unnecessarily downloading a file from the go.dev site. It was also not providing enough data to fix the issue when the test failed. Fixes golang/go#52671 Change-Id: Ie42501c197395538376debd510cfb993d697401d Reviewed-on: https://go-review.googlesource.com/c/build/+/405516 Run-TryBot: Carlos Amedee <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Auto-Submit: Carlos Amedee <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 140d723 commit 5d48fa5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/gomote/gomote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func (s *Server) WriteFileFromURL(ctx context.Context, req *protos.WriteFileFrom
478478
return nil, status.Errorf(codes.Aborted, "failed to get file from URL: %s", err)
479479
}
480480
if resp.StatusCode != http.StatusOK {
481-
return nil, status.Errorf(codes.Aborted, "unable to get file from URL: response code: %d", resp.StatusCode)
481+
return nil, status.Errorf(codes.Aborted, "unable to get file from %q: response code: %d", req.GetUrl(), resp.StatusCode)
482482
}
483483
rc = resp.Body
484484
}

internal/gomote/gomote_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"errors"
1313
"fmt"
1414
"io"
15+
"net/http"
16+
"net/http/httptest"
1517
"testing"
1618
"time"
1719

@@ -788,9 +790,13 @@ func TestWriteFileFromURL(t *testing.T) {
788790
ctx := access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP())
789791
client := setupGomoteTest(t, context.Background())
790792
gomoteID := mustCreateInstance(t, client, fakeIAP())
793+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
794+
fmt.Fprintln(w, "Go is an open source programming language")
795+
}))
796+
defer ts.Close()
791797
if _, err := client.WriteFileFromURL(ctx, &protos.WriteFileFromURLRequest{
792798
GomoteId: gomoteID,
793-
Url: `https://go.dev/dl/go1.17.6.linux-amd64.tar.gz`,
799+
Url: ts.URL,
794800
Filename: "foo",
795801
Mode: 0777,
796802
}); err != nil {

0 commit comments

Comments
 (0)