Debian Codegraph @

tests/thirdparty/config.go

raw symbols SCIP
1 // Package thirdparty executes integration tests based on third-party projects that use avo.
2 package thirdpartyscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/
3
4 import (
5 "encoding/jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/"
6 "errorsscip-go gomod github.com/golang/go/src go1.18 errors/"
7 "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/"
8 "ioscip-go gomod github.com/golang/go/src go1.18 io/"
9 "osscip-go gomod github.com/golang/go/src go1.18 os/"
10 "pathscip-go gomod github.com/golang/go/src go1.18 path/"
11 "path/filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/"
12 "sortscip-go gomod github.com/golang/go/src go1.18 sort/"
13 "stringsscip-go gomod github.com/golang/go/src go1.18 strings/"
14 "timescip-go gomod github.com/golang/go/src go1.18 time/"
15 )
16
17 // GithubRepository specifies a repository on github.
18 type GithubRepositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository# struct {
19 Ownerscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#Owner. string `json:"owner"`
20 Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#Name. string `json:"name"`
21 }
22
23 func (r GithubRepositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#) Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#String().() string {
24 return pathscip-go gomod github.com/golang/go/src go1.18 path/.Joinscip-go gomod github.com/golang/go/src go1.18 path/Join().(r.Ownerscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#Owner., r.Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#Name.)
25 }
26
27 // URL returns the Github repository URL.
28 func (r GithubRepositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#) URLscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#URL().() string {
29 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("https://github.com/%s", r)
30 }
31
32 // CloneURL returns the git clone URL.
33 func (r GithubRepositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#) CloneURLscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#CloneURL().() string {
34 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("https://github.com/%s.git", r)
35 }
36
37 // Metadata about the repository.
38 type Metadatascip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Metadata# struct {
39 // Repository description.
40 Descriptionscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Metadata#Description. string `json:"description,omitempty"`
41
42 // Homepage URL. Not the same as the Github page.
43 Homepagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Metadata#Homepage. string `json:"homepage,omitempty"`
44
45 // Number of Github stars.
46 Starsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Metadata#Stars. int `json:"stars,omitempty"`
47 }
48
49 // Project defines an integration test based on a third-party project using avo.
50 type Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project# struct {
51 // Repository for the project. At the moment, all projects are available on
52 // github.
53 Repositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Repository. GithubRepositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository# `json:"repository"`
54
55 // Repository metadata.
56 Metadatascip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Metadata. Metadatascip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Metadata# `json:"metadata"`
57
58 // Default git branch. This is used when testing against the latest version.
59 DefaultBranchscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#DefaultBranch. string `json:"default_branch,omitempty"`
60
61 // Version as a git sha, tag or branch.
62 Versionscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Version. string `json:"version"`
63
64 // If the project test has a known problem, record it by setting this to a
65 // non-zero avo issue number. If set, the project will be skipped in
66 // testing.
67 KnownIssuescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#KnownIssue. int `json:"known_issue,omitempty"`
68
69 // Packages within the project to test.
70 Packagesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Packages. []*Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package# `json:"packages"`
71 }
72
73 func (p *Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#) defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#defaults().(set bool) {
74 for _, pkg := range p.Packagesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Packages. {
75 pkg.defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#defaults().(set)
76 }
77 }
78
79 // Validate project definition.
80 func (p *Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#) Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Validate().() error {
81 if p.DefaultBranchscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#DefaultBranch. == "" {
82 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("missing default branch")
83 }
84 if p.Versionscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Version. == "" {
85 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("missing version")
86 }
87 if len(p.Packagesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Packages.) == 0 {
88 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("missing packages")
89 }
90 for _, pkg := range p.Packagesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Packages. {
91 if err := pkg.Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Validate().(); err != nil {
92 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("package %s: %w", pkg.Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Name().(), err)
93 }
94 }
95 return nil
96 }
97
98 // ID returns an identifier for the project.
99 func (p *Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#) IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#ID().() string {
100 return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.18 strings/ReplaceAll().(p.Repositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Repository..Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#String().(), "/", "-")
101 }
102
103 // Skip reports whether the project test should be skipped. If skipped, a known
104 // issue will be set.
105 func (p *Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#) Skipscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Skip().() bool {
106 return p.KnownIssuescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#KnownIssue. != 0
107 }
108
109 // Reason returns the reason why the test is skipped.
110 func (p *Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#) Reasonscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Reason().() string {
111 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("https://github.com/mmcloughlin/avo/issues/%d", p.KnownIssuescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#KnownIssue.)
112 }
113
114 // Step represents a set of commands to run as part of the testing plan for a
115 // third-party package.
116 type Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step# struct {
117 Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Name. string `json:"name,omitempty"`
118 WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#WorkingDirectory. string `json:"dir,omitempty"`
119 Commandsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Commands. []string `json:"commands"`
120 }
121
122 // Validate step parameters.
123 func (s *Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#) Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Validate().() error {
124 if s.Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Name. == "" {
125 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("missing name")
126 }
127 if len(s.Commandsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Commands.) == 0 {
128 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("missing commands")
129 }
130 return nil
131 }
132
133 // Package defines an integration test for a package within a project.
134 type Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package# struct {
135 // Sub-package within the project under test. Used as the root directory for
136 // the test unless explicitly overridden.
137 SubPackagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#SubPackage. string `json:"pkg,omitempty"`
138
139 // Path to the module file for the avo generator package. This is necessary
140 // so the integration test can insert replace directives to point at the avo
141 // version under test.
142 Modulescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Module. string `json:"module"`
143
144 // Root directory for all steps in the test. All file path references will
145 // be relative to this directory. If empty, the sub-package directory is
146 // used, or otherwise the root of the repository.
147 Rootscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Root. string `json:"root,omitempty"`
148
149 // Setup steps. These run prior to the insertion of avo replace directives,
150 // therefore should be used if it's necessary to initialize new go modules
151 // within the repository.
152 Setupscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Setup. []*Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step# `json:"setup,omitempty"`
153
154 // Steps to run the avo code generator.
155 Generatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Generate. []*Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step# `json:"generate"`
156
157 // Test steps. If empty, defaults to "go test ./...".
158 Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Test. []*Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step# `json:"test,omitempty"`
159 }
160
161 // defaults sets or removes default field values.
162 func (p *Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#) defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#defaults().(set bool) {
163 for _, stage := range []struct {
164 Steps []*Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#
165 DefaultName string
166 }{
167 {p.Setupscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Setup., "Setup"},
168 {p.Generatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Generate., "Generate"},
169 {p.Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Test., "Test"},
170 } {
171 if len(stage.Steps) == 1 {
172 stage.Steps[0].Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Name. = applydefaultscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/applydefault().(set, stage.Steps[0].Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Name., stage.DefaultName)
173 }
174 }
175 }
176
177 func applydefaultscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/applydefault().(set bool, s, def string) string {
178 switch {
179 case set && s == "":
180 return def
181 case !set && s == def:
182 return ""
183 default:
184 return s
185 }
186 }
187
188 // Validate package definition.
189 func (p *Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#) Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Validate().() error {
190 if p.Modulescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Module. == "" {
191 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("missing module")
192 }
193 if len(p.Generatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Generate.) == 0 {
194 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("no generate commands")
195 }
196
197 stages := map[string][]*Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#{
198 "setup": p.Setupscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Setup.,
199 "generate": p.Generatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Generate.,
200 "test": p.Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Test.,
201 }
202 for name, steps := range stages {
203 for _, s := range steps {
204 if err := s.Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Validate().(); err != nil {
205 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("%s step: %w", name, err)
206 }
207 }
208 }
209
210 return nil
211 }
212
213 // Name of the package.
214 func (p *Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#) Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Name().() string {
215 if p.IsRootscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#IsRoot().() {
216 return "root"
217 }
218 return p.SubPackagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#SubPackage.
219 }
220
221 // IsRoot reports whether the package is the root of the containing project.
222 func (p *Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#) IsRootscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#IsRoot().() bool {
223 return p.SubPackagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#SubPackage. == ""
224 }
225
226 // WorkingDirectory returns the base directory for all steps in the test.
227 func (p *Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#) WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#WorkingDirectory().() string {
228 if p.Rootscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Root. != "" {
229 return p.Rootscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Root.
230 }
231 if p.SubPackagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#SubPackage. != "" {
232 return p.SubPackagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#SubPackage.
233 }
234 return ""
235 }
236
237 // Context specifies execution environment parameters for a third-party test.
238 type Contextscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context# struct {
239 // Path to the avo version under test.
240 AvoDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context#AvoDirectory. string
241
242 // Path to the checked out third-party repository.
243 RepositoryDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context#RepositoryDirectory. string
244 }
245
246 // Steps generates the list of steps required to execute the integration test
247 // for this package. Context specifies execution environment parameters.
248 func (p *Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#) Stepsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Steps().(c *Contextscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context#) []*Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step# {
249 var steps []*Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#
250
251 // Optional setup.
252 steps = append(steps, p.Setupscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Setup....)
253
254 // Replace avo dependency.
255 const invalid = "v0.0.0-00010101000000-000000000000"
256 moddir := filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Dir().(p.Modulescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Module.)
257 modfile := filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Base().(p.Modulescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Module.)
258 steps = append(steps, &Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#{
259 Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Name.: "Avo Module Replacement",
260 WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#WorkingDirectory.: moddir,
261 Commandsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Commands.: []string{
262 "go mod edit -modfile=" + modfile + " -require=github.com/mmcloughlin/avo@" + invalid,
263 "go mod edit -modfile=" + modfile + " -replace=github.com/mmcloughlin/avo=" + c.AvoDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context#AvoDirectory.,
264 "go mod tidy -modfile=" + modfile,
265 },
266 })
267
268 // Run generation.
269 steps = append(steps, p.Generatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Generate....)
270
271 // Display changes.
272 steps = append(steps, &Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#{
273 Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Name.: "Diff",
274 Commandsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Commands.: []string{"git diff"},
275 })
276
277 // Tests.
278 if len(p.Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Test.) > 0 {
279 steps = append(steps, p.Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Test....)
280 } else {
281 steps = append(steps, &Stepscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#{
282 Namescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Name.: "Test",
283 Commandsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Commands.: []string{
284 "go test ./...",
285 },
286 })
287 }
288
289 // Prepend sub-directory to every step.
290 if dir := p.WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#WorkingDirectory().(); dir != "" {
291 for _, s := range steps {
292 s.WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#WorkingDirectory. = filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Join().(dir, s.WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#WorkingDirectory.)
293 }
294 }
295
296 return steps
297 }
298
299 // Test case for a given package within a project.
300 type Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test# struct {
301 Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project. *Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#
302 Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Package. *Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#
303 }
304
305 // ID returns an identifier for the test case.
306 func (t *Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#) IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#ID().() string {
307 pkgpath := pathscip-go gomod github.com/golang/go/src go1.18 path/.Joinscip-go gomod github.com/golang/go/src go1.18 path/Join().(t.Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project..Repositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Repository..Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#String().(), t.Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Package..SubPackagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#SubPackage.)
308 return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.18 strings/ReplaceAll().(pkgpath, "/", "-")
309 }
310
311 // Projects is a collection of third-party integration tests.
312 type Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects# []*Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#
313
314 func (p Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#) defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#defaults().(set bool) {
315 for _, prj := range p {
316 prj.defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#defaults().(set)
317 }
318 }
319
320 // Validate the project collection.
321 func (p Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#) Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Validate().() error {
322 // Projects are valid.
323 for _, prj := range p {
324 if err := prj.Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Validate().(); err != nil {
325 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("project %s: %w", prj.IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#ID().(), err)
326 }
327 }
328
329 // No duplicate project IDs.
330 pid := map[string]bool{}
331 for _, prj := range p {
332 id := prj.IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#ID().()
333 if pid[id] {
334 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("duplicate project %q", id)
335 }
336 pid[id] = true
337 }
338
339 // No duplicate test IDs.
340 tid := map[string]bool{}
341 for _, t := range p.Testsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Tests().() {
342 id := t.IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#ID().()
343 if tid[id] {
344 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("duplicate test %q", id)
345 }
346 tid[id] = true
347 }
348
349 return nil
350 }
351
352 // Tests returns all test cases for the projects collection.
353 func (p Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#) Testsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Tests().() []*Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test# {
354 var ts []*Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#
355 for _, prj := range p {
356 for _, pkg := range prj.Packagesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Packages. {
357 ts = append(ts, &Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#{
358 Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project.: prj,
359 Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Package.: pkg,
360 })
361 }
362 }
363 return ts
364 }
365
366 // Ranked returns a copy of the projects list ranked in desending order of
367 // popularity.
368 func (p Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#) Rankedscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Ranked().() Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects# {
369 ranked := append(Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#(nil), p...)
370 sortscip-go gomod github.com/golang/go/src go1.18 sort/.SliceStablescip-go gomod github.com/golang/go/src go1.18 sort/SliceStable().(ranked, func(i, j int) bool {
371 return ranked[i].Metadatascip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Metadata..Starsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Metadata#Stars. > ranked[j].Metadatascip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Metadata..Starsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Metadata#Stars.
372 })
373 return ranked
374 }
375
376 // Top returns the top n most popular projects.
377 func (p Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#) Topscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Top().(n int) Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects# {
378 top := p.Rankedscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Ranked().()
379 if len(top) > n {
380 top = top[:n]
381 }
382 return top
383 }
384
385 // Suite defines a third-party test suite.
386 type Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite# struct {
387 // Projects to test.
388 Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#Projects. Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects# `json:"projects"`
389
390 // Time of the last update to project metadata.
391 MetadataLastUpdatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#MetadataLastUpdate. timescip-go gomod github.com/golang/go/src go1.18 time/.Timescip-go gomod github.com/golang/go/src go1.18 time/Time# `json:"metadata_last_update"`
392 }
393
394 func (s *Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#) defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#defaults().(set bool) {
395 s.Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#Projects..defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#defaults().(set)
396 }
397
398 // Validate the test suite.
399 func (s *Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#) Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#Validate().() error {
400 if s.MetadataLastUpdatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#MetadataLastUpdate..IsZeroscip-go gomod github.com/golang/go/src go1.18 time/Time#IsZero().() {
401 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("empty metadata update time")
402 }
403
404 if s.MetadataLastUpdatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#MetadataLastUpdate..Locationscip-go gomod github.com/golang/go/src go1.18 time/Time#Location().() != timescip-go gomod github.com/golang/go/src go1.18 time/.UTCscip-go gomod github.com/golang/go/src go1.18 time/UTC. {
405 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("metadata update time not in UTC")
406 }
407
408 if err := s.Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#Projects..Validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Validate().(); err != nil {
409 return err
410 }
411
412 return nil
413 }
414
415 // LoadSuite loads a test suite from JSON format.
416 func LoadSuitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/LoadSuite().(r ioscip-go gomod github.com/golang/go/src go1.18 io/.Readerscip-go gomod github.com/golang/go/src go1.18 io/Reader#) (*Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#, error) {
417 var s *Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#
418 d := jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.NewDecoderscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/NewDecoder().(r)
419 d.DisallowUnknownFieldsscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Decoder#DisallowUnknownFields().()
420 if err := d.Decodescip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Decoder#Decode().(&s); err != nil {
421 return nil, err
422 }
423 s.defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#defaults().(true)
424 return s, nil
425 }
426
427 // LoadSuiteFile loads a test suite from a JSON file.
428 func LoadSuiteFilescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/LoadSuiteFile().(filename string) (*Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#, error) {
429 f, err := osscip-go gomod github.com/golang/go/src go1.18 os/.Openscip-go gomod github.com/golang/go/src go1.18 os/Open().(filename)
430 if err != nil {
431 return nil, err
432 }
433 defer f.Closescip-go gomod github.com/golang/go/src go1.18 os/File#Close().()
434 return LoadSuitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/LoadSuite().(f)
435 }
436
437 // StoreSuite writes a test suite in JSON format.
438 func StoreSuitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/StoreSuite().(w ioscip-go gomod github.com/golang/go/src go1.18 io/.Writerscip-go gomod github.com/golang/go/src go1.18 io/Writer#, s *Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#) error {
439 e := jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.NewEncoderscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/NewEncoder().(w)
440 e.SetIndentscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Encoder#SetIndent().("", " ")
441 s.defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#defaults().(false)
442 err := e.Encodescip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Encoder#Encode().(s)
443 s.defaultsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#defaults().(true)
444 return err
445 }
446
447 // StoreSuiteFile writes a test suite to a JSON file.
448 func StoreSuiteFilescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/StoreSuiteFile().(filename string, s *Suitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#) error {
449 f, err := osscip-go gomod github.com/golang/go/src go1.18 os/.Createscip-go gomod github.com/golang/go/src go1.18 os/Create().(filename)
450 if err != nil {
451 return err
452 }
453 defer f.Closescip-go gomod github.com/golang/go/src go1.18 os/File#Close().()
454 return StoreSuitescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/StoreSuite().(f, s)
455 }