Skip to content

test: assert e2e resources through cli reads#26

Merged
guoqqqi merged 2 commits into
api7:mainfrom
guoqqqi:test/e2e-cli-resource-assertions
Apr 28, 2026
Merged

test: assert e2e resources through cli reads#26
guoqqqi merged 2 commits into
api7:mainfrom
guoqqqi:test/e2e-cli-resource-assertions

Conversation

@guoqqqi
Copy link
Copy Markdown
Contributor

@guoqqqi guoqqqi commented Apr 28, 2026

Summary

  • keep existing mock Admin API unit tests untouched
  • remove real proxy-chain assertions from Ginkgo scenario/upstream coverage
  • assert created resources via CLI get/list-style reads against real APISIX Admin API
  • support APISIX upstream nodes returned as either object or array so route list is robust against real Admin API data

Verification

Copilot AI review requested due to automatic review settings April 28, 2026 03:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Warning

Rate limit exceeded

@guoqqqi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 48 minutes and 28 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ffb874a9-6bf3-4757-8a7b-7aa107225e6c

📥 Commits

Reviewing files that changed from the base of the PR and between 0792850 and 92a0e31.

📒 Files selected for processing (8)
  • pkg/api/types_route.go
  • pkg/api/types_service.go
  • pkg/api/types_stream_route.go
  • pkg/api/types_upstream.go
  • pkg/api/types_upstream_nodes.go
  • pkg/api/types_upstream_nodes_test.go
  • test/e2e/scenario_coverage_ginkgo_test.go
  • test/e2e/upstream_ginkgo_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates E2E coverage to validate created APISIX resources via CLI get/list reads (instead of exercising proxy-chain traffic assertions) and hardens the API client types to handle APISIX upstream node formats returned by the real Admin API.

Changes:

  • Refactor E2E “scenario coverage” and upstream health scenarios to assert resources via a6 ... get JSON reads.
  • Add api.UpstreamNodes with a custom JSON unmarshaler to support upstream nodes returned as either an object map or an array of host/port/weight entries.
  • Update Route/Service/Upstream/StreamRoute API types to use UpstreamNodes, with new unit tests covering both node encodings.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/e2e/upstream_ginkgo_test.go Reworks health-check test to assert persisted config via upstream get JSON output.
test/e2e/scenario_coverage_ginkgo_test.go Replaces real gateway traffic assertions with CLI read-based resource assertions.
pkg/api/types_upstream_nodes.go Introduces UpstreamNodes and custom JSON unmarshaling for object/array node formats.
pkg/api/types_upstream_nodes_test.go Adds unit tests for unmarshaling both upstream node representations.
pkg/api/types_upstream.go Switches Upstream.Nodes to UpstreamNodes.
pkg/api/types_route.go Switches inline route upstream Nodes to UpstreamNodes.
pkg/api/types_service.go Switches inline service upstream Nodes to UpstreamNodes.
pkg/api/types_stream_route.go Switches inline stream route upstream Nodes to UpstreamNodes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +12 to +16
func (n *UpstreamNodes) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
*n = nil
return nil
}
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnmarshalJSON compares string(data) == "null" without trimming whitespace. JSON values passed to UnmarshalJSON may include leading/trailing spaces/newlines, so inputs like " null " will currently fall through and error. Consider bytes.TrimSpace(data) (and similarly trimming node.Weight) before comparing against null/"null" to make decoding robust.

Copilot uses AI. Check for mistakes.
Comment thread pkg/api/types_upstream_nodes.go Outdated
Comment on lines +40 to +46
var weight interface{} = 1
if len(node.Weight) > 0 && string(node.Weight) != "null" {
if err := json.Unmarshal(node.Weight, &weight); err != nil {
return err
}
}
nodes[key] = weight
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the array-form parsing, the default weight is set as an int (var weight interface{} = 1), while encoding/json unmarshals numeric values into float64 when targeting interface{}. This can produce mixed numeric types in the same UpstreamNodes map (e.g., float64(2) vs int(1)), which is easy for callers to mishandle. Consider defaulting to float64(1) so numeric weights have a consistent type.

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +28
func TestUpstreamNodesUnmarshalArray(t *testing.T) {
var nodes UpstreamNodes
if err := json.Unmarshal([]byte(`[{"host":"127.0.0.1","port":9080,"weight":2}]`), &nodes); err != nil {
t.Fatalf("unmarshal array nodes: %v", err)
}

if got := nodes["127.0.0.1:9080"]; got != float64(2) {
t.Fatalf("unexpected node weight: %#v", got)
}
}
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new UpstreamNodes unmarshaler adds behavior beyond the current tests (e.g., trimming/handling whitespace around null, and defaulting a missing weight to 1 in the array form). Consider adding unit tests that cover these edge cases (e.g., nodes: null with surrounding whitespace, and an array entry missing weight) to prevent regressions.

Copilot uses AI. Check for mistakes.
@guoqqqi
Copy link
Copy Markdown
Contributor Author

guoqqqi commented Apr 28, 2026

Addressed the Copilot review comments by trimming JSON input/weight values before null checks, using float64(1) for default array-form node weights, and adding unit coverage for null nodes plus default weights.

@guoqqqi guoqqqi merged commit 17c1c30 into api7:main Apr 28, 2026
6 checks passed
@guoqqqi guoqqqi deleted the test/e2e-cli-resource-assertions branch April 28, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants