-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathlist_test.go
More file actions
98 lines (81 loc) · 2.99 KB
/
Copy pathlist_test.go
File metadata and controls
98 lines (81 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0
package profile
import (
"context"
"testing"
"go.uber.org/mock/gomock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/mindersec/minder/internal/util/cli"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
mockv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1/mock"
)
//nolint:paralleltest // Cannot run in parallel because it swaps global Viper/Stdout state
func TestListCommand(t *testing.T) {
tests := []cli.CmdTestCase{
{
Name: "list profiles table success",
Args: []string{"profile", "list"},
MockSetup: func(t *testing.T, ctrl *gomock.Controller) context.Context {
t.Helper()
client := mockv1.NewMockProfileServiceClient(ctrl)
mockResp := &minderv1.ListProfilesResponse{}
cli.LoadFixture(t, "mock_profile_list.json", mockResp)
client.EXPECT().
ListProfiles(gomock.Any(), gomock.Any()).
Return(mockResp, nil)
return cli.WithRPCClient[minderv1.ProfileServiceClient](context.Background(), client)
},
GoldenFileName: "list_profiles_table.txt",
},
{
Name: "list profiles yaml success",
Args: []string{"profile", "list", "-o", "yaml"},
MockSetup: func(t *testing.T, ctrl *gomock.Controller) context.Context {
t.Helper()
client := mockv1.NewMockProfileServiceClient(ctrl)
mockResp := &minderv1.ListProfilesResponse{}
cli.LoadFixture(t, "mock_profile_list.json", mockResp)
client.EXPECT().
ListProfiles(gomock.Any(), gomock.Any()).
Return(mockResp, nil)
return cli.WithRPCClient[minderv1.ProfileServiceClient](context.Background(), client)
},
GoldenFileName: "list_profiles.yaml",
},
{
Name: "list profiles with label filter",
Args: []string{"profile", "list", "-l", "test-label"},
MockSetup: func(t *testing.T, ctrl *gomock.Controller) context.Context {
t.Helper()
client := mockv1.NewMockProfileServiceClient(ctrl)
mockResp := &minderv1.ListProfilesResponse{Profiles: []*minderv1.Profile{}}
client.EXPECT().
ListProfiles(gomock.Any(), gomock.Any()).
Return(mockResp, nil)
return cli.WithRPCClient[minderv1.ProfileServiceClient](context.Background(), client)
},
GoldenFileName: "list_profiles_filtered.txt",
},
{
Name: "failure invalid format",
Args: []string{"profile", "list", "-o", "invalid"},
ExpectedError: "invalid argument",
},
{
Name: "failure server error",
Args: []string{"profile", "list"},
MockSetup: func(t *testing.T, ctrl *gomock.Controller) context.Context {
t.Helper()
client := mockv1.NewMockProfileServiceClient(ctrl)
client.EXPECT().
ListProfiles(gomock.Any(), gomock.Any()).
Return(nil, status.Error(codes.Internal, "database connection failed"))
return cli.WithRPCClient[minderv1.ProfileServiceClient](context.Background(), client)
},
ExpectedError: "database connection failed",
},
}
cli.RunCmdTests(t, tests, ProfileCmd)
}