Debian Codegraph @

cmd/gorelease/testdata/README.md

raw symbols SCIP
1 This directory contains most tests for gorelease. Each test runs gorelease (the
2 `runRelease` function) with a given set of flags in a temporary directory
3 populated with files specified in the test itself or files from the module test
4 proxy. The output is compared against a golden `want` file specified in the
5 test.
6
7 ## Test flags
8
9 A specific test may be run with a command like:
10
11 go test -run=TestRelease/basic/v0_patch_suggest
12
13 where `basic/v0_patch_suggest` matches the file
14 `testdata/basic/v0_patch_suggest.test`.
15
16 The `-u` flag adds or updates the `want` file in each test to match the output.
17 This is useful for fixing tests after an intended change in behavior.
18
19 go test -run=TestRelease/basic/v0_patch_suggest -u
20
21 The `-testwork` flag instructs the test framework to leave the test's temporary
22 directory and module proxy in place after running the test. This is useful
23 for debugging.
24
25 ## Test format
26
27 Tests are written in `.test` files in `testdata` subdirectories. Each `.test`
28 file is a valid txtar file (see `golang.org/x/tools/txtar`). The comment section
29 contains the test parameters, which are a series of `key=value` pairs. Blank
30 lines and comments starting with `#` are allowed in this section. Valid keys
31 are:
32
33 * `mod`: sets the module path. Must be specified together with `version`. Copies
34 the content of a module out of the test proxy into a temporary directory
35 where `gorelease` is run.
36 * `version`: specified together with `mod`, it sets the version to retrieve from
37 the test proxy. See more information below.
38 * `base`: the value of the `-base` flag passed to `gorelease`.
39 * `release`: the value of the `-version` flag passed to `gorelease`.
40 * `dir`: the directory where `gorelease` should be invoked. Useful when the test
41 describes a whole repository, and `gorelease` should be invoked in a
42 subdirectory.
43 * `error`: true if the test expects a hard error. False by default.
44 * `success`: true if the test expects a report to be printed with no errors
45 or diagnostics. True by default.
46 * `skip`: non-empty if the test should be skipped. The value is a string passed
47 to `t.Skip`.
48 * `proxyVersions`: empty if the test should include all `mod/` entries in the
49 proxy, or else a comma-separated list of the modpath@version's it should
50 include.
51
52 Test archives have a file named `want`, containing the expected output of the
53 test. A test will fail if the actual output differs from `want`.
54
55 If the `mod` and `version` parameters are not set, other files will be extracted
56 to the temporary directory where `gorelease` runs.
57
58 ## Populating module contents
59
60 When building a test in `testdata/`, there are two ways to populate the module
61 directory being tested:
62
63 ### Option 1: inline
64
65 You can inline files in the `.test` folder as described in
66 https://pkg.go.dev/golang.org/x/tools/txtar#hdr-Txtar_format. For example,
67
68 ```
69 -- some.file --
70 the contents
71 of the file
72 ```
73
74 ### Option 2: specify an existing file
75
76 Often, multiple tests want to share the same setup - the same files. So, users
77 can write these common files in `testdata/mod/`, and use one of these files as
78 the module directory contents.
79
80 To specify a file in `testdata/mod/` to use as the module contents.
81
82 ## Module format
83
84 Tests run with `GOPROXY` set to a local URL that points to a test proxy. The
85 test proxy serves modules described by `.txt` files in the `testdata/mod/`
86 subdirectory.
87
88 Each module is a txtar archive named `$modpath_$version.txt` where `$modpath`
89 is the module path (with slashes replaced with underscores) and `$version` is
90 the version. If the archive contains a file named `.mod`, that will be used to
91 respond to `.mod` requests; otherwise, `go.mod` will be used (`.mod` is only
92 necessary for modules that lack `go.mod` files). If the archive contains a
93 file named `.info`, that will be used to respond to `.info` requests; otherwise,
94 `.info` is synthesized from the version. All other files in the archive are
95 packed into a `.zip` file to satisfy `.zip` requests.