-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathartifact_list_test.go
More file actions
73 lines (62 loc) · 2.21 KB
/
Copy pathartifact_list_test.go
File metadata and controls
73 lines (62 loc) · 2.21 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
// SPDX-FileCopyrightText: Copyright 2026 The Minder Authors
// SPDX-License-Identifier: Apache-2.0
package artifact
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 TestArtifactListCommand(t *testing.T) {
setupSuccess := func(t *testing.T, ctrl *gomock.Controller) context.Context {
t.Helper()
client := mockv1.NewMockArtifactServiceClient(ctrl)
mockResp := &minderv1.ListArtifactsResponse{}
cli.LoadFixture(t, "mock_artifact_list.json", mockResp)
client.EXPECT().
ListArtifacts(gomock.Any(), gomock.Any()).
Return(mockResp, nil).
Times(1)
return cli.WithRPCClient[minderv1.ArtifactServiceClient](context.Background(), client)
}
tests := []cli.CmdTestCase{
{
Name: "list artifacts - table output",
Args: []string{"artifact", "list", "-o", "table"},
MockSetup: setupSuccess,
GoldenFileName: "artifact_list.table",
},
{
Name: "list artifacts - yaml output",
Args: []string{"artifact", "list", "-o", "yaml"},
MockSetup: setupSuccess,
GoldenFileName: "artifact_list.yaml",
},
{
Name: "list artifacts with from filter",
Args: []string{"artifact", "list", "--from", "repository=org/repo", "-o", "table"},
MockSetup: setupSuccess,
GoldenFileName: "artifact_list_from.table",
},
{
Name: "server error handling",
Args: []string{"artifact", "list"},
MockSetup: func(t *testing.T, ctrl *gomock.Controller) context.Context {
t.Helper()
client := mockv1.NewMockArtifactServiceClient(ctrl)
client.EXPECT().
ListArtifacts(gomock.Any(), gomock.Any()).
Return(nil, status.Error(codes.Internal, "internal server error")).
Times(1)
return cli.WithRPCClient[minderv1.ArtifactServiceClient](context.Background(), client)
},
ExpectedError: "internal server error",
},
}
cli.RunCmdTests(t, tests, ArtifactCmd)
}