MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestShareLinkCreateJSONOutputsLinkMetadata

Function TestShareLinkCreateJSONOutputsLinkMetadata

cmd/share_link_json_test.go:29–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestShareLinkCreateJSONOutputsLinkMetadata(t *testing.T) {
30 expires := dropbox.DBXTime(time.Date(2026, 7, 1, 0, 0, 0, 0, time.UTC))
31 stubSharedLinkClient(t, &mockSharedLinkClient{
32 createSharedLinkWithSettingsFn: func(arg *sharing.CreateSharedLinkWithSettingsArg) (sharing.IsSharedLinkMetadata, error) {
33 link := sharedLinkFile("/docs/report.txt", "https://example.com/report")
34 link.Id = "id:file"
35 link.Expires = &expires
36 link.Size = 42
37 return link, nil
38 },
39 })
40
41 var stdout bytes.Buffer
42 cmd := &cobra.Command{}
43 cmd.SetOut(&stdout)
44 setShareLinkOutputJSON(t, cmd)
45
46 if err := shareLinkCreate(cmd, []string{"/docs/report.txt"}); err != nil {
47 t.Fatalf("shareLinkCreate error: %v", err)
48 }
49
50 got := decodeShareLinkOperationOutput[shareLinkCreateInput, shareLinkJSONMetadata](t, stdout.Bytes())
51 if got.Input.Path != "/docs/report.txt" {
52 t.Fatalf("input.path = %q, want /docs/report.txt", got.Input.Path)
53 }
54 if len(got.Results) != 1 {
55 t.Fatalf("results = %d, want 1", len(got.Results))
56 }
57 result := got.Results[0]
58 if result.Status != shareLinkJSONStatusCreated || result.Kind != "file" {
59 t.Fatalf("operation result = %#v, want created file", result)
60 }
61 if result.Result.Type != "file" || result.Result.URL != "https://example.com/report" || result.Result.PathLower != "/docs/report.txt" {
62 t.Fatalf("result = %#v, want file shared link metadata", result.Result)
63 }
64 if result.Result.Size == nil || *result.Result.Size != 42 {
65 t.Fatalf("result.size = %#v, want 42", result.Result.Size)
66 }
67 if result.Result.Expires == nil || *result.Result.Expires != "2026-07-01T00:00:00Z" {
68 t.Fatalf("result.expires = %#v, want RFC3339 expiration", result.Result.Expires)
69 }
70 assertNoTopLevelJSONField(t, stdout.Bytes(), "existing")
71}
72
73func TestShareLinkCreateJSONReportsExistingAsStatus(t *testing.T) {
74 existing := sharedLinkFolder("/docs", "https://example.com/docs")

Callers

nothing calls this directly

Calls 6

stubSharedLinkClientFunction · 0.85
sharedLinkFileFunction · 0.85
setShareLinkOutputJSONFunction · 0.85
shareLinkCreateFunction · 0.85

Tested by

no test coverage detected