@@ -23,6 +23,11 @@ import (
2323 "os"
2424 "strings"
2525 "testing"
26+
27+ "google.golang.org/protobuf/encoding/protojson"
28+
29+ adminv2 "kmesh.net/kmesh/api/v2/admin"
30+ cluster "kmesh.net/kmesh/api/v2/cluster"
2631)
2732
2833func TestUint32ToIPStr (t * testing.T ) {
@@ -145,3 +150,41 @@ func TestNewCmd(t *testing.T) {
145150 t .Errorf ("--output default = %q, want %q" , f .DefValue , "table" )
146151 }
147152}
153+
154+ func TestPrintKernelNativeTable (t * testing.T ) {
155+ dump := & adminv2.ConfigDump {
156+ StaticResources : & adminv2.ConfigResources {
157+ ClusterConfigs : []* cluster.Cluster {
158+ {Name : "outbound|80|default|svc.cluster.local" },
159+ },
160+ },
161+ }
162+ body , err := protojson .Marshal (dump )
163+ if err != nil {
164+ t .Fatalf ("failed to marshal ConfigDump: %v" , err )
165+ }
166+
167+ out := captureStdout (t , func () { printKernelNativeTable (body ) })
168+ if ! strings .Contains (out , "NAME" ) {
169+ t .Error ("expected NAME header in output" )
170+ }
171+ if ! strings .Contains (out , "outbound|80|default|svc.cluster.local" ) {
172+ t .Error ("expected cluster name in output" )
173+ }
174+ }
175+
176+ func TestPrintKernelNativeTable_EmptyDump (t * testing.T ) {
177+ dump := & adminv2.ConfigDump {}
178+ body , _ := protojson .Marshal (dump )
179+ out := captureStdout (t , func () { printKernelNativeTable (body ) })
180+ if strings .TrimSpace (out ) != "" {
181+ t .Errorf ("expected empty output for empty dump, got: %s" , out )
182+ }
183+ }
184+
185+ func TestPrintKernelNativeTable_InvalidJSON (t * testing.T ) {
186+ out := captureStdout (t , func () { printKernelNativeTable ([]byte ("{bad" )) })
187+ if ! strings .Contains (out , "{bad" ) {
188+ t .Error ("expected raw fallback output on invalid JSON" )
189+ }
190+ }
0 commit comments