I am getting this output:
Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestListRelationshipsCmd$ github.com/layer5io/meshery/mesheryctl/internal/cli/root/relationships
--- FAIL: TestListRelationshipsCmd (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x30aad57]
goroutine 12 [running]:
testing.tRunner.func1.2({0x34cffc0, 0x5275b90})
/usr/local/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1635 +0x35e
panic({0x34cffc0?, 0x5275b90?})
/usr/local/go/src/runtime/panic.go:785 +0x132
github.com/layer5io/meshery/mesheryctl/internal/cli/root/relationships.init.func4(0x52c5c60, {0x546de80?, 0x4?, 0x38d0976?})
/home/sujai/meshery/mesheryctl/internal/cli/root/relationships/list.go:66 +0x317
github.com/spf13/cobra.(*Command).execute(0x52c5c60, {0x546de80, 0x0, 0x0})
/home/sujai/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:985 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0x52c6500)
/home/sujai/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
/home/sujai/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1041
github.com/layer5io/meshery/mesheryctl/internal/cli/root/relationships.TestListRelationshipsCmd(0xc000031a00)
/home/sujai/meshery/mesheryctl/internal/cli/root/relationships/relationship_test.go:31 +0x10d
testing.tRunner(0xc000031a00, 0x3a7c350)
/usr/local/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
/usr/local/go/src/testing/testing.go:1743 +0x390
FAIL github.com/layer5io/meshery/mesheryctl/internal/cli/root/relationships 0.045s
FAIL
I wrote this code while writing tests:
package relationships
import (
"bytes"
"testing"
"github.com/layer5io/meshery/mesheryctl/pkg/utils"
"github.com/stretchr/testify/assert"
)
func TestListRelationshipsCmd(t *testing.T) {
utils.SetupContextEnv(t)
actual := new(bytes.Buffer)
RelationshipCmd.SetOut(actual)
RelationshipCmd.SetErr(actual)
RelationshipCmd.SetArgs([]string{"list"})
err := RelationshipCmd.Execute()
assert.Nil(t, err, "list command should execute successfully")
assert.Contains(t, actual.String(), "Total number of relationships", "list command should print list of relationships")
}