Skip to content

Commit b17664c

Browse files
dmitshurgopherbot
authored andcommitted
internal/task: simplify test case inputs in TestTweetRelease
tweetImage was simplified to not use the go.dev/dl/?mode=json API without breaking tests. This change simplifies the test cases to have minimal local inputs without needing to use the internet. Fixes golang/go#57062. Change-Id: I09098413824f2338eccfac69c208c170fa125a77 Reviewed-on: https://go-review.googlesource.com/c/build/+/504520 Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent dbf1467 commit b17664c

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

internal/task/tweet_test.go

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package task
77
import (
88
"bytes"
99
"context"
10-
"encoding/json"
1110
"flag"
1211
"fmt"
1312
"image"
@@ -23,34 +22,6 @@ import (
2322
)
2423

2524
func TestTweetRelease(t *testing.T) {
26-
if testing.Short() {
27-
// This test is useful when modifying the tweet text and image templates,
28-
// but don't run it in -short mode since—for a New York minute only—this
29-
// test involves making some HTTP GET requests to the internet.
30-
t.Skip("skipping test that hits go.dev/dl/?mode=json read-only API in -short mode")
31-
}
32-
33-
// Fetch real Go release file metadata for use in test cases below.
34-
resp, err := http.Get("https://go.dev/dl/?mode=json&include=all")
35-
if err != nil {
36-
t.Fatal(err)
37-
}
38-
defer resp.Body.Close()
39-
if resp.StatusCode != http.StatusOK {
40-
t.Fatalf("non-200 OK status code: %v", resp.Status)
41-
} else if ct := resp.Header.Get("Content-Type"); ct != "application/json" {
42-
t.Fatalf("got Content-Type %q, want %q", ct, "application/json")
43-
}
44-
var releases []WebsiteRelease
45-
err = json.NewDecoder(resp.Body).Decode(&releases)
46-
if err != nil {
47-
t.Fatal(err)
48-
}
49-
var filesByVersion = make(map[string][]WebsiteFile)
50-
for _, r := range releases {
51-
filesByVersion[r.Version] = r.Files
52-
}
53-
5425
tests := [...]struct {
5526
name string
5627
published []Published
@@ -62,8 +33,11 @@ func TestTweetRelease(t *testing.T) {
6233
{
6334
name: "minor",
6435
published: []Published{
65-
{Version: "go1.17.1", Files: filesByVersion["go1.17.1"]},
66-
{Version: "go1.16.8", Files: filesByVersion["go1.16.8"]},
36+
{Version: "go1.17.1", Files: []WebsiteFile{{
37+
OS: "linux", Arch: "arm64",
38+
Filename: "go1.17.1.linux-arm64.tar.gz", Size: 102606384, Kind: "archive"}},
39+
},
40+
{Version: "go1.16.8"},
6741
},
6842
security: "Includes security fixes for A and B.",
6943
announcement: "https://groups.google.com/g/golang-announce/c/dx9d7IOseHw/m/KNH37k37AAAJ",
@@ -90,8 +64,11 @@ $ go1.17.1 version
9064
go version go1.17.1 linux/arm64` + "\n",
9165
},
9266
{
93-
name: "minor-solo",
94-
published: []Published{{Version: "go1.11.1", Files: filesByVersion["go1.11.1"]}},
67+
name: "minor-solo",
68+
published: []Published{{Version: "go1.11.1", Files: []WebsiteFile{{
69+
OS: "darwin", Arch: "amd64",
70+
Filename: "go1.11.1.darwin-amd64.tar.gz", Size: 124181190, Kind: "archive"}},
71+
}},
9572
announcement: "https://groups.google.com/g/golang-announce/c/pFXKAfoVJqw",
9673
randomSeed: 23,
9774
wantLog: `tweet text:
@@ -114,8 +91,11 @@ $ go1.11.1 version
11491
go version go1.11.1 darwin/amd64` + "\n",
11592
},
11693
{
117-
name: "beta",
118-
published: []Published{{Version: "go1.17beta1", Files: filesByVersion["go1.17beta1"]}},
94+
name: "beta",
95+
published: []Published{{Version: "go1.17beta1", Files: []WebsiteFile{{
96+
OS: "darwin", Arch: "amd64",
97+
Filename: "go1.17beta1.darwin-amd64.tar.gz", Size: 135610703, Kind: "archive"}},
98+
}},
11999
announcement: "https://groups.google.com/g/golang-announce/c/i4EliPDV9Ok/m/MxA-nj53AAAJ",
120100
randomSeed: 678,
121101
wantLog: `tweet text:
@@ -140,8 +120,11 @@ $ go1.17beta1 version
140120
go version go1.17beta1 darwin/amd64` + "\n",
141121
},
142122
{
143-
name: "rc",
144-
published: []Published{{Version: "go1.17rc2", Files: filesByVersion["go1.17rc2"]}},
123+
name: "rc",
124+
published: []Published{{Version: "go1.17rc2", Files: []WebsiteFile{{
125+
OS: "windows", Arch: "arm64",
126+
Filename: "go1.17rc2.windows-arm64.zip", Size: 116660997, Kind: "archive"}},
127+
}},
145128
announcement: "https://groups.google.com/g/golang-announce/c/yk30ovJGXWY/m/p9uUnKbbBQAJ",
146129
randomSeed: 456,
147130
wantLog: `tweet text:
@@ -166,8 +149,11 @@ $ go1.17rc2 version
166149
go version go1.17rc2 windows/arm64` + "\n",
167150
},
168151
{
169-
name: "major",
170-
published: []Published{{Version: "go1.17", Files: filesByVersion["go1.17"]}},
152+
name: "major",
153+
published: []Published{{Version: "go1.17", Files: []WebsiteFile{{
154+
OS: "freebsd", Arch: "amd64",
155+
Filename: "go1.17.freebsd-amd64.tar.gz", Size: 133579378, Kind: "archive"}},
156+
}},
171157
security: "Includes a super duper security fix (CVE-123).",
172158
randomSeed: 123,
173159
wantLog: `tweet text:

0 commit comments

Comments
 (0)