Repository navigation
fix(integration): guard unguarded X(...)[0] indexing in the nwo test harness - #1923
Conversation
|
Hey @mbrandenburger 👋 thanks for the PR! This comment updates automatically as you push changes -- think of it as your PR's live scoreboard! PR Checks✅ DCO Sign-off -- All commits have valid sign-offs. Nice work! ❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:
You'll need to sign your commits with GPG (e.g. ✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing! ✅ Issue Link -- Linked to #1918 (assigned to you). ⏳ All checks must pass before this PR can be reviewed. You've got this! |
…harness Several call sites read the first element of a platform/peer/org lookup without checking that the collection was non-empty, or type-asserted a platform without checking the assertion. On an unexpected topology (e.g. a peer org with no peers, or no fabric/fsc platform registered) these panicked with a generic "index out of range" or interface-conversion message instead of a clear test failure explaining what was expected. Guard each site with the gomega.Expect(...).To(gomega.HaveLen(1)) / ok-checked type-assertion idiom already used in integration/fabric/configupdate/configupdate.go, so a violated invariant fails the spec with a descriptive message: - integration/integration.go: ViewCmd's fsc platform lookup - integration/fabric/runtimeconfig/commands.go: InjectAll's fabric platform lookup - integration/nwo/fabric/platform.go: UserByOrg, UsersByOrg, InvokeChaincode and ConnectionProfile's peer/org lookups - integration/nwo/monitoring/monitoring/monitoring.go: fscScrapes and fscCryptoDir's fsc platform lookup Document when each guarded function fails the test, and add unit tests exercising both the happy path and the guard panics in platform.go and monitoring.go. Tests use only testify/require in their bodies; a package-level TestMain registers gomega's fail handler to panic (mirroring integration.go's Ginkgo setup) so the guarded gomega.Expect calls raise a catchable panic under go test. Fixes hyperledger-labs#1918 Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
225b994 to
0767b4e
Compare
Summary
nwotest-harness call sites that read the first element of a platform/peer/org lookup, or type-assert a platform, without checking the collection is non-empty or the assertion succeeded. On an unexpected topology these panicked with a generic index-out-of-range or interface-conversion message; they now fail the spec with a descriptivegomega.Expectmessage.integration.go'sViewCmd,runtimeconfig/commands.go'sInjectAll,nwo/fabric/platform.go'sUserByOrg/UsersByOrg/InvokeChaincode/ConnectionProfile, andnwo/monitoring/monitoring/monitoring.go'sfscScrapes/fscCryptoDir.Test plan
make checks(lint + go fix) — 0 issues across all modulesgo test ./nwo/fabric/... ./nwo/monitoring/... -v— all tests passFixes #1918