@@ -79,52 +79,61 @@ SHA2-256(output.bin)= c74ce73165c288348b168baffc477b6db38af3c629b42a7725c35d99d4
7979
8080There are a couple of basic tests, including one integration test.
8181
82- To run the unit tests:
82+ In this section we focus on unit test. The integration tests are covered in the
83+ next section.
84+
85+ To run all unit tests:
8386
8487``` bash
85- ❯ go test -v ./communities
86- === RUN TestUpload_Success
87- --- PASS: TestUpload_Success (0.00s)
88- === RUN TestDownload_Success
89- --- PASS: TestDownload_Success (0.00s)
90- === RUN TestDownloadWithContext_Cancel
91- --- PASS: TestDownloadWithContext_Cancel (0.04s)
92- PASS
93- ok go-codex-client/communities 0.044s
88+ ❯ go test -v ./communities -count 1
9489```
9590
96- To run the integration test, use ` integration ` tag and narrow the scope using ` -run Integration ` :
91+ To be more selective, e.g. in order to run all the tests from
92+ ` CodexArchiveDownloaderSuite ` , run:
9793
9894``` bash
99- go test -v -tags=integration ./communities -run Integration -timeout 15s
95+ go test -v ./communities -run CodexArchiveDownloader -count 1
10096```
10197
102- To make sure that the test is actually run and not cached, use ` count ` option :
98+ or for an individual test from that suite :
10399
104100``` bash
105- go test -v -tags=integration ./communities -run Integration -timeout 15s -count 1
101+ go test -v ./communities -run TestCodexArchiveDownloaderSuite/TestCancellationDuringPolling -count 1
106102```
107103
108- ### Using gotestsum to run the tests
109-
110104You can also use
` gotestsum ` to run the tests (you may need to install it first, e.g.
` go install gotest.tools/[email protected] ` ):
111105
112106``` bash
113- gotestsum --packages=" ./communities" -f testname --rerun-fails -- -run " TestCodexArchiveDownloaderSuite " - count 1
107+ gotestsum --packages=" ./communities" -f testname --rerun-fails -- -count 1
114108```
115109
116- or to run all tests ( including CodexClient tests) :
110+ For a more verbose output including logs use ` -f standard-verbose ` , e.g. :
117111
118112``` bash
119- gotestsum --packages=" ./communities" -f testname --rerun-fails -- -count 1
113+ gotestsum --packages=" ./communities" -f standard-verbose --rerun-fails -- -v -count 1
120114```
121115
122- For a more verbose output including logs use ` -f standard-verbose ` , e.g.:
116+ To be more selective, e.g. in order to run all the tests from
117+ ` CodexArchiveDownloaderSuite ` , run:
118+
119+ ``` bash
120+ gotestsum --packages=" ./communities" -f testname --rerun-fails -- -run CodexArchiveDownloader -count 1
121+ ```
122+
123+ or for an individual test from that suite:
124+
125+ ``` bash
126+ gotestsum --packages=" ./communities" -f testname --rerun-fails -- -run TestCodexArchiveDownloaderSuite/TestCancellationDuringPolling -count 1
127+ ```
128+
129+ Notice, that the ` -run ` flag accepts a regular expression that matches against the full test path, so you can be more concise in naming if necessary, e.g.:
123130
124131``` bash
125- gotestsum --packages=" ./communities" -f standard-verbose --rerun-fails -- -run " TestCodexArchiveDownloaderSuite " -v -count 1
132+ gotestsum --packages=" ./communities" -f testname --rerun-fails -- -run CodexArchiveDownloader/Cancellation -count 1
126133```
127134
135+ This also applies to native ` go test ` command.
136+
128137### Running integration tests
129138
130139When building Codex client for testing like here, I often remove some logging noise, by slightly changing the build params in ` build.nims ` :
@@ -145,16 +154,41 @@ To start Codex client, use e.g.:
145154./build/codex --data-dir=./data-1 --listen-addrs=/ip4/127.0.0.1/tcp/8081 --api-port=8001 --nat=none --disc-port=8091 --log-level=TRACE
146155```
147156
148- Then to run archive downloader integration tests :
157+ To run the integration test, use ` codex_integration ` tag and narrow the scope using ` -run Integration ` :
149158
150159``` bash
151- CODEX_API_PORT=8001 gotestsum --packages=" ./communities" -f standard-verbose --rerun-fails -- -tags=integration -run " TestCodexArchiveDownloaderIntegrationSuite" -v -count 1
160+ CODEX_API_PORT=8001 go test -v -tags=codex_integration ./communities -run Integration -timeout 15s
161+ ```
162+
163+ This will run all integration tests, including CodexClient integration tests.
164+
165+ To make sure that the test is actually run and not cached, use ` count ` option:
166+
167+ ``` bash
168+ CODEX_API_PORT=8001 go test -v -tags=codex_integration ./communities -run Integration -timeout 15s -count 1
169+ ```
170+
171+ To be more specific and only run the tests related to, e.g. index downloader or archive
172+ downloader you can use:
173+
174+ ``` bash
175+ CODEX_API_PORT=8001 go test -v -tags=codex_integration ./communities -run CodexIndexDownloaderIntegration -timeout 15s -count 1
176+
177+ CODEX_API_PORT=8001 go test -v -tags=codex_integration ./communities -run CodexArchiveDownloaderIntegration -timeout 15s -count 1
178+ ```
179+
180+ and then, if you prefer to use ` gotestsum ` :
181+
182+ ``` bash
183+ CODEX_API_PORT=8001 gotestsum --packages=" ./communities" -f standard-verbose --rerun-fails -- -tags=codex_integration -run CodexIndexDownloaderIntegration -v -count 1
184+
185+ CODEX_API_PORT=8001 gotestsum --packages=" ./communities" -f standard-verbose --rerun-fails -- -tags=codex_integration -run CodexArchiveDownloaderIntegration -v -count 1
152186```
153187
154- or to run all integration tests:
188+ or to run all integration tests (including CodexClient integration tests) :
155189
156190``` bash
157- CODEX_API_PORT=8001 gotestsum --packages=" ./communities" -f standard-verbose --rerun-fails -- -tags=integration -v -count 1 -run Integration
191+ CODEX_API_PORT=8001 gotestsum --packages=" ./communities" -f standard-verbose --rerun-fails -- -tags=codex_integration -v -count 1 -run Integration
158192```
159193
160194I prefer to be more selective when running integration tests.
0 commit comments