Commit 52f30ba
authored
Refine testify assertions in tests for clearer failures and lint-aligned patterns (#4051)
This PR addresses the Go Fan/testify review by replacing low-signal
assertion patterns with more specific testify assertions across the
reported test areas. The goal is to improve failure diagnostics and
align tests with current assertion best practices without changing
production behavior.
- **Assertion specificity cleanup**
- Replaced boolean equality assertions with direct boolean assertions:
- `assert.Equal(t, true/false, ...)` → `assert.True(...)` /
`assert.False(...)`
- Replaced generic substring checks:
- `assert.True(t, strings.Contains(...))` → `assert.Contains(...)`
- `assert.False(t, strings.Contains(...))` → `assert.NotContains(...)`
- Replaced length-comparison boolean assertions:
- `assert.True(t, len(x) <= N)` → `assert.LessOrEqual(t, len(x), N)`
- Replaced one compound substring OR check with `assert.Regexp(...)` for
direct intent.
- **Typed-nil error assertion handling in `rules_test.go`**
- The five `require.Nil(t, err)` sites were updated to
`require.NoError(...)` semantics while preserving behavior for typed-nil
`*ValidationError` returns.
- Added a tiny adapter helper used only in tests:
- `validationErrAsError(err *ValidationError) error`
- **Test import cleanup**
- Removed now-unused `strings` imports in files where
`assert.Contains`/`assert.NotContains` replaced manual
`strings.Contains` calls.
```go
// Before
assert.True(t, strings.Contains(text, "Bug report"), "response text should contain the issue title")
// After
assert.Contains(t, text, "Bug report", "response text should contain the issue title")
```
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build850057972/b514/launcher.test
/tmp/go-build850057972/b514/launcher.test
-test.testlogfile=/tmp/go-build850057972/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s E=3 .cfg /tmp/go-build403-w
x_amd64/vet . --gdwarf2 --64 x_amd64/vet -I .cfg
TiyY/dyEj6sNqXXBEEx-BTiyY x_amd64/vet --gdwarf-5 g/grpc/internal/-qE -o
x_amd64/vet` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build850057972/b496/config.test
/tmp/go-build850057972/b496/config.test
-test.testlogfile=/tmp/go-build850057972/b496/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build850057972/b394/vet.cfg @v1.1.3/cpu/x86/-errorsas -I
x_amd64/vet --gdwarf-5 .io/otel/baggage-atomic -o x_amd64/vet 2483��
g_.a L_XeGB1fo x_amd64/vet -p vendor/golang.or-atomic -lang=go1.25
x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build772277680/b224/config.test
/tmp/go-build772277680/b224/config.test
-test.testlogfile=/tmp/go-build772277680/b224/testlog.txt
-test.paniconexit0 -test.timeout=10m0s rtcf�� by/280457505e8d1REDACTED y
ache/go/1.25.8/x64/pkg/tool/linujson
ntime.v2.task/mo/usr/libexec/docker/cli-plugins/docker-buildx
-ifaceassert -nilfunc ache/go/1.25.8/x64/pkg/tool/linu--no-legend
"SSL�� ef5286be851aaba1bad991c168a5fac9-- -tests
ker/cli-plugins/docker-compose by/c68777e185eb8node
ache/go/1.25.8/xmock-mcp-server.js x_amd64/vet fce/log.json` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build850057972/b514/launcher.test
/tmp/go-build850057972/b514/launcher.test
-test.testlogfile=/tmp/go-build850057972/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s E=3 .cfg /tmp/go-build403-w
x_amd64/vet . --gdwarf2 --64 x_amd64/vet -I .cfg
TiyY/dyEj6sNqXXBEEx-BTiyY x_amd64/vet --gdwarf-5 g/grpc/internal/-qE -o
x_amd64/vet` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build850057972/b514/launcher.test
/tmp/go-build850057972/b514/launcher.test
-test.testlogfile=/tmp/go-build850057972/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s E=3 .cfg /tmp/go-build403-w
x_amd64/vet . --gdwarf2 --64 x_amd64/vet -I .cfg
TiyY/dyEj6sNqXXBEEx-BTiyY x_amd64/vet --gdwarf-5 g/grpc/internal/-qE -o
x_amd64/vet` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build850057972/b523/mcp.test
/tmp/go-build850057972/b523/mcp.test
-test.testlogfile=/tmp/go-build850057972/b523/testlog.txt
-test.paniconexit0 -test.timeout=10m0s .cfg�� 2483721/b343/_pkg_.a -fPIC
x_amd64/vet us.pb.go g/grpc/balancer -fmessage-length=0 x_amd64/vet
.cfg�� /oidc/errors.go /oidc/provider.go x_amd64/vet -dynout
g/grpc/health/gr/usr/bin/runc -ffile-prefix-ma--version x_amd64/vet`
(dns block)
> - Triggering command: `/tmp/go-build772277680/b484/mcp.test
/tmp/go-build772277680/b484/mcp.test
-test.testlogfile=/tmp/go-build772277680/b484/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -ato�� -bool y
etc/ssl/certs/ca-certificates.crt",
"REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certifi 3cfebab8779a2365/check
-ifaceassert -nilfunc noffline 287f��
ef5286be851aaba1bad991c168a5fac9/run/containerd/io.containerd.runtime.v2.task/moby/5878ee59bbb48go
3cfebab8779a2365c0a0927369ddf64be3c02162ae57d53bf27 /usr/bin/grep
9381bd4d1eab940e/usr/bin/runc.original` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>12 files changed
Lines changed: 38 additions & 25 deletions
File tree
- internal
- config
- rules
- difc
- mcp
- middleware
- proxy
- server
- test/integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1089 | 1089 | | |
1090 | 1090 | | |
1091 | 1091 | | |
1092 | | - | |
| 1092 | + | |
1093 | 1093 | | |
1094 | 1094 | | |
1095 | 1095 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
566 | 565 | | |
567 | 566 | | |
568 | 567 | | |
569 | | - | |
| 568 | + | |
570 | 569 | | |
571 | 570 | | |
572 | 571 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
249 | 252 | | |
250 | 253 | | |
251 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
12 | 19 | | |
13 | 20 | | |
14 | 21 | | |
| |||
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
77 | | - | |
| 84 | + | |
78 | 85 | | |
79 | 86 | | |
80 | 87 | | |
| |||
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
141 | | - | |
| 148 | + | |
142 | 149 | | |
143 | 150 | | |
144 | 151 | | |
| |||
295 | 302 | | |
296 | 303 | | |
297 | 304 | | |
298 | | - | |
| 305 | + | |
299 | 306 | | |
300 | 307 | | |
301 | 308 | | |
| |||
899 | 906 | | |
900 | 907 | | |
901 | 908 | | |
902 | | - | |
| 909 | + | |
903 | 910 | | |
904 | 911 | | |
905 | 912 | | |
| |||
1039 | 1046 | | |
1040 | 1047 | | |
1041 | 1048 | | |
1042 | | - | |
| 1049 | + | |
1043 | 1050 | | |
1044 | 1051 | | |
1045 | 1052 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
590 | 589 | | |
591 | 590 | | |
592 | 591 | | |
593 | | - | |
| 592 | + | |
594 | 593 | | |
595 | 594 | | |
596 | 595 | | |
597 | | - | |
| 596 | + | |
598 | 597 | | |
599 | 598 | | |
600 | 599 | | |
| |||
616 | 615 | | |
617 | 616 | | |
618 | 617 | | |
619 | | - | |
| 618 | + | |
620 | 619 | | |
621 | 620 | | |
622 | 621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
272 | 274 | | |
273 | 275 | | |
274 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
685 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
686 | 690 | | |
687 | 691 | | |
688 | 692 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
574 | 573 | | |
575 | 574 | | |
576 | 575 | | |
577 | | - | |
| 576 | + | |
578 | 577 | | |
0 commit comments