Skip to content

Commit f646366

Browse files
committed
internal/testing/integration: add test for duplicate symbols
An integration test is added for these cases: - A symbol changes across different build contexts - A symbol is introduced at different versions for different build contexts - The package symbol for a symbol changes because its parent changes, but the name and synopsis are the same For golang/go#37102 Change-Id: Ieca17042e11b2fd583e2133a3064ab6043a29858 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/316969 Trust: Julie Qiu <[email protected]> Run-TryBot: Julie Qiu <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent f4fd399 commit f646366

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

internal/proxy/testdata/[email protected]

+15
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func HelloJS() string {
112112

113113
package multigoos
114114

115+
// Different signature from CloseOnExec for linux and darwin.
115116
func CloseOnExec(foo string) error {
116117
return nil
117118
}
@@ -121,6 +122,20 @@ func CloseOnExec(foo string) error {
121122

122123
package multigoos
123124

125+
// Different signature from CloseOnExec for windows.
124126
func CloseOnExec(num int) (int, error) {
125127
return num, nil
126128
}
129+
130+
-- duplicate/duplicate.go --
131+
// +build linux darwin
132+
133+
package duplicate
134+
135+
// Unexported here, exported in v1.2.0.
136+
type tokenType int
137+
138+
// Token types.
139+
const (
140+
TokenShort tokenType = iota
141+
)

internal/proxy/testdata/[email protected]

+31
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,34 @@ package multigoos
129129

130130
func CloseOnExec(n int) {
131131
}
132+
133+
-- duplicate/duplicate.go --
134+
// +build linux darwin
135+
136+
package duplicate
137+
138+
type TokenType int
139+
140+
// Token types.
141+
const (
142+
TokenShort TokenType = iota
143+
)
144+
145+
-- duplicate/duplicate_windows.go --
146+
// +build windows
147+
148+
package duplicate
149+
150+
// Constant here, type for JS, linux and darwin.
151+
const TokenType = 3
152+
153+
-- duplicate/duplicate_js.go --
154+
// +build js
155+
156+
package duplicate
157+
158+
// Exported here, unexported in v1.1.0.
159+
type TokenType struct {
160+
}
161+
162+
func TokenShort() TokenType { return &TokenType{} }

internal/testing/integration/data_frontend_versions_test.go

+87
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,93 @@ package integration
66

77
import "golang.org/x/pkgsite/internal/frontend"
88

9+
var versionsPageMultiGoosDuplicates = []*frontend.VersionList{
10+
{
11+
VersionListKey: frontend.VersionListKey{
12+
ModulePath: "example.com/symbols",
13+
Major: "v1",
14+
},
15+
Versions: []*frontend.VersionSummary{
16+
{
17+
CommitTime: "Jan 30, 2019",
18+
Link: "/example.com/[email protected]/duplicate",
19+
Retracted: false,
20+
RetractionRationale: "",
21+
Version: "v1.2.0",
22+
IsMinor: true,
23+
Symbols: [][]*frontend.Symbol{
24+
{
25+
{
26+
Name: "TokenType",
27+
Synopsis: "const TokenType",
28+
Link: "/example.com/[email protected]/duplicate?GOOS=windows#TokenType",
29+
New: true,
30+
Section: "Constants",
31+
Kind: "Constant",
32+
Builds: []string{"windows/amd64"},
33+
},
34+
},
35+
{
36+
{
37+
Name: "TokenType",
38+
Synopsis: "type TokenType int",
39+
Link: "/example.com/[email protected]/duplicate?GOOS=darwin#TokenType",
40+
New: true,
41+
Section: "Types",
42+
Kind: "Type",
43+
Builds: []string{"darwin/amd64", "linux/amd64"},
44+
// Children is nil because TokenShort was first
45+
// introduced at an earlier version.
46+
// Its parent and section changed at this version,
47+
// but we don't surface that information.
48+
},
49+
{
50+
Name: "TokenType",
51+
Synopsis: "type TokenType struct",
52+
Link: "/example.com/[email protected]/duplicate?GOOS=js#TokenType",
53+
New: true,
54+
Section: "Types",
55+
Kind: "Type",
56+
Children: []*frontend.Symbol{
57+
{
58+
Name: "TokenShort",
59+
Synopsis: "func TokenShort() TokenType",
60+
Link: "/example.com/[email protected]/duplicate?GOOS=js#TokenShort",
61+
New: true,
62+
Section: "Types",
63+
Kind: "Function",
64+
},
65+
},
66+
Builds: []string{"js/wasm"},
67+
},
68+
},
69+
},
70+
},
71+
{
72+
CommitTime: "Jan 30, 2019",
73+
Link: "/example.com/[email protected]/duplicate",
74+
Retracted: false,
75+
RetractionRationale: "",
76+
Version: "v1.1.0",
77+
IsMinor: true,
78+
Symbols: [][]*frontend.Symbol{
79+
{
80+
{
81+
Name: "TokenShort",
82+
Synopsis: "const TokenShort",
83+
Link: "/example.com/[email protected]/duplicate?GOOS=darwin#TokenShort",
84+
New: true,
85+
Section: "Constants",
86+
Kind: "Constant",
87+
Builds: []string{"darwin/amd64", "linux/amd64"},
88+
},
89+
},
90+
},
91+
},
92+
},
93+
},
94+
}
95+
996
var versionsPageMultiGoos = []*frontend.VersionList{
1097
{
1198
VersionListKey: frontend.VersionListKey{

internal/testing/integration/frontend_versions_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func TestFrontendVersionsPage(t *testing.T) {
5252
}{
5353
{"versions page symbols - one version all symbols", modulePath, versionsPageSymbols},
5454
{"versions page hello - multi GOOS", modulePath + "/hello", versionsPageHello},
55-
{"versions page duplicate symbols multi GOOS", modulePath + "/multigoos", versionsPageMultiGoos},
55+
{"versions page - test symbol signature is different for different build context", modulePath + "/multigoos", versionsPageMultiGoos},
56+
{"versions page - test symbol is introduced at different versions for different build context and changes across versions",
57+
modulePath + "/duplicate", versionsPageMultiGoosDuplicates},
5658
} {
5759
t.Run(test.name, func(t *testing.T) {
5860
urlPath := fmt.Sprintf("/%s?tab=versions&m=json", test.pkgPath)

0 commit comments

Comments
 (0)