Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
86fd505
feat(mesh): add mesh command container and resource discovery
justindavies Aug 4, 2026
f271dcf
feat(mesh): read any resource type from a Kong Mesh 3 control plane
justindavies Sep 9, 2026
13a155d
feat(mesh): create and delete mesh resources
justindavies Sep 9, 2026
3d0c96d
feat(mesh): issue dataplane and zone tokens
justindavies Sep 9, 2026
88d9211
feat(mesh): list control planes and select one by name
justindavies Sep 9, 2026
dcd7059
fix(mesh): satisfy the linter on yaml import and an unused parameter
justindavies Sep 9, 2026
12fe535
feat(mesh): surface control plane warnings on create
justindavies Sep 15, 2026
66a5680
fix(mesh): honor explicit control plane selection, stop shadowing --p…
justindavies Sep 16, 2026
cc2458e
fix(mesh): paginate collections, register the explicit path, modernize
justindavies Sep 16, 2026
e4d2282
fix(mesh): build HTTP clients from the configured timeout and transport
justindavies Sep 16, 2026
1c3e302
fix(mesh): define the configuration contract for the remaining options
justindavies Sep 16, 2026
e4ebac5
feat(mesh): make apply the primary verb for sending resources
justindavies Sep 16, 2026
b744b38
feat(mesh): support self managed control planes
justindavies Sep 16, 2026
834c5ad
refactor(mesh): name the shared column headers
justindavies Sep 16, 2026
76761c5
refactor(mesh): drop the inspection type option, which moves with ins…
justindavies Sep 16, 2026
5de9af0
fix(mesh): resolve the target once, and scope TLS to its destination
justindavies Sep 17, 2026
0134a8e
fix(mesh): bind mesh flags in the mesh command, not in each caller
justindavies Sep 17, 2026
c80ca25
refactor(mesh)!: write resources with apply only, not create
justindavies Sep 17, 2026
8cd9a0d
test(mesh): cover the environment rung and add mesh e2e scenarios
justindavies Sep 17, 2026
8cdb6fa
refactor(mesh): drop the per-verb flag binding the mesh command now does
justindavies Sep 17, 2026
2881399
test(mesh): exercise the real HTTP path, including the TLS isolation fix
justindavies Sep 18, 2026
0fca846
test(mesh): pin explicit selector precedence at the command level
justindavies Sep 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions internal/cmd/root/mesh_command_paths_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package root

import (
"strings"
"testing"

meshcommon "github.com/kong/kongctl/internal/cmd/root/products/konnect/mesh/common"
)

// Mesh is reachable both directly and under the explicit product path. The
// constructors promise both, but only the direct form was registered, so
// `kongctl get konnect mesh` failed with "unknown command". These assert the
// real command paths rather than the constructors.
func TestMeshCommandPathsResolve(t *testing.T) {
// Every verb Kong Mesh serves here. For Plan, Sync, Diff, Export, Apply
// and Delete, konnect.NewKonnectCmd replaces the konnect command with the
// declarative command and returns before any product is added, so
// `apply konnect mesh` and `delete konnect mesh` cannot be registered
// without restructuring that subtree. Those two are served by the direct
// form only, and fall through to the declarative command rather than
// erroring -- asserted below so the fall-through stays deliberate.
paths := [][]string{
{"apply", "mesh", "--help"},
{"get", "mesh", "--help"},
{"get", "konnect", "mesh", "--help"},
{"create", "mesh", "--help"},
{"create", "konnect", "mesh", "--help"},
{"delete", "mesh", "--help"},
}

for _, args := range paths {
path := strings.Join(args[:len(args)-1], " ")

t.Run(path, func(t *testing.T) {
result := executeRootForTest(t, args...)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add request-level command tests and dedicated Mesh E2E scenarios.

The additional tests are useful, but these command-path tests execute only --help, which bypasses the bindings and requests that currently fail on the explicit Konnect path. Selector tests exercise flag detection rather than the combined URL/authentication decision. TestMeshOptionPrecedence also claims environment coverage but contains no environment-variable case.

Add complete command/HTTP tests for direct and explicit paths, selector/authentication combinations, file/environment/flag precedence, pagination, TLS credential isolation, and write behavior. Add isolated Mesh discovery/read, apply/get/delete, and token E2E scenarios with cleanup, and run them through trusted E2E. There are still no Mesh scenarios in this PR; passing smoke/version does not validate the feature.


if result.exitCode != 0 {
t.Fatalf("expected %q to succeed\nstdout:\n%s\nstderr:\n%s",
path, result.stdout, result.stderr)
}
if strings.Contains(result.stderr, "unknown command") {
t.Fatalf("expected %q to be registered\nstderr:\n%s", path, result.stderr)
}
// The mesh command's own help, not a parent's help that merely
// lists it: a swallowed argument prints the parent's help and
// still exits zero.
if !strings.Contains(result.stdout, "Kong Mesh control plane") {
t.Fatalf("expected %q help to describe the mesh command\nstdout:\n%s",
path, result.stdout)
}
})
}
}

// The declarative verbs claim `<verb> konnect`, so mesh is not reachable
// there. That is a property of the konnect subtree rather than a mesh bug, but
// it is silent -- the declarative command accepts "mesh" as a positional
// argument and prints its own help -- so it is pinned here. If either of these
// ever resolves to the mesh command, meshVerbs and this test disagree.
func TestMeshIsNotReachableUnderTheDeclarativeVerbs(t *testing.T) {
for _, verb := range []string{"apply", "delete"} {
t.Run(verb, func(t *testing.T) {
result := executeRootForTest(t, verb, "konnect", "mesh", "--help")

if strings.Contains(result.stdout, "Kong Mesh control plane") {
t.Fatalf("%s konnect mesh now resolves to the mesh command; "+
"add %q to meshVerbs and move it into TestMeshCommandPathsResolve\nstdout:\n%s",
verb, verb, result.stdout)
}
})
}
}

// A selector given on the command line must reach configuration on both
// command trees.
//
// The explicit path passed the general konnect pre-run, which binds only the
// konnect-common flags, so every mesh flag there was registered but unbound.
// The failure was silent in the worst way: with a control plane already in
// configuration, `get konnect mesh meshes --control-plane-url <other>` ignored
// the flag and listed the configured control plane instead.
func TestMeshFlagsBindOnBothCommandTrees(t *testing.T) {
// A port nothing listens on. The request must be attempted and fail to
// connect, which proves the flag reached configuration. --help would not:
// it returns before the pre-run binds anything, which is why a help-only
// test cannot catch this.
const wantURL = "http://127.0.0.1:1"

paths := [][]string{
{"get", "mesh", "meshes"},
{"get", "konnect", "mesh", "meshes"},
}

for _, path := range paths {
name := strings.Join(path, " ")

t.Run(name, func(t *testing.T) {
args := append(append([]string{}, path...), "--control-plane-url", wantURL)
result := executeRootForTest(t, args...)

if currConfig == nil {
t.Fatal("expected config to be initialized")
}
if got := currConfig.GetString(meshcommon.ControlPlaneURLConfigPath); got != wantURL {
t.Fatalf("%s: control plane URL = %q, want %q (flag registered but not bound)",
name, got, wantURL)
}
// The selector must also decide the request. Binding it while
// sending the request elsewhere is the failure this guards.
if !strings.Contains(result.stderr, "127.0.0.1:1") {
t.Fatalf("%s: expected the request to address %s\nstderr:\n%s",
name, wantURL, result.stderr)
}
})
}
}

// Resource writes belong to apply. `create mesh -f` reached the same upsert
// and so replaced an existing resource while reporting "updated", without the
// operator asking for a replacement, so it was removed. Token issuance stays
// under create.
func TestCreateMeshOffersTokensNotResourceWrites(t *testing.T) {
t.Run("the -f flag is gone", func(t *testing.T) {
result := executeRootForTest(t, "create", "mesh", "-f", "policy.yaml")

if result.exitCode == 0 {
t.Fatalf("expected create mesh -f to be rejected\nstdout:\n%s", result.stdout)
}
if !strings.Contains(result.stderr, "shorthand flag: 'f'") {
t.Fatalf("expected an unknown-flag error for -f\nstderr:\n%s", result.stderr)
}
})

t.Run("token subcommands remain", func(t *testing.T) {
for _, sub := range []string{"zone-token", "dataplane-token"} {
result := executeRootForTest(t, "create", "mesh", sub, "--help")
if result.exitCode != 0 {
t.Fatalf("create mesh %s should still resolve\nstderr:\n%s", sub, result.stderr)
}
}
})

t.Run("apply still takes -f", func(t *testing.T) {
result := executeRootForTest(t, "apply", "mesh", "--help")
if !strings.Contains(result.stdout, "-f") {
t.Fatalf("expected apply mesh to offer -f\nstdout:\n%s", result.stdout)
}
})
}
Loading
Loading