github.com/cilium/cilium@v1.16.2/pkg/command/output_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package command 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestDumpJSON(t *testing.T) { 13 type sampleData struct { 14 ID int 15 Name string 16 } 17 18 tt := sampleData{ 19 ID: 1, 20 Name: "test", 21 } 22 23 err := dumpJSON(tt, "") 24 require.NoError(t, err) 25 26 err = dumpJSON(tt, "{.Id}") 27 require.NoError(t, err) 28 29 err = dumpJSON(tt, "{{.Id}}") 30 if err == nil { 31 t.Fatalf("Dumpjson jsonpath no error with invalid path '%s'", err) 32 } 33 } 34 35 func TestDumpYAML(t *testing.T) { 36 type sampleData struct { 37 ID int 38 Name string 39 } 40 41 tt := sampleData{ 42 ID: 1, 43 Name: "test", 44 } 45 46 err := dumpYAML(tt) 47 require.NoError(t, err) 48 }