Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.48.1 - Unreleased

- Sites: preserve requested false booleans in `sites get` JSON. The default mask keeps `starred` and `hasThumbnail` when they are false, and a custom mask that names `trashed` keeps `trashed` when it is false. (#1308) — thanks @SebTardif.

## 0.48.0 - 2026-11-05

**Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates.
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (c *SitesGetCmd) Run(ctx context.Context, flags *RootFlags) error {
}

if outfmt.IsJSON(ctx) {
forceRequestedDriveFileBools(f, mask)
return outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{"site": f})
}

Expand Down
89 changes: 89 additions & 0 deletions internal/cmd/sites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,92 @@ func TestSitesGetRejectsNonSite(t *testing.T) {
t.Fatalf("expected url not-site error, got %v", err)
}
}

// TestSitesGet_JSONKeepsRequestedFalseBools proves sites get JSON keeps
// requested boolean fields when they are false. drive.File tags them
// omitempty, so starred and hasThumbnail disappear unless ForceSendFields
// is set. Drive get already does that; sites get must too.
func TestSitesGet_JSONKeepsRequestedFalseBools(t *testing.T) {
cases := []struct {
name string
args []string
body map[string]any
want map[string]bool
notWant []string
}{
{
name: "default fields",
args: []string{"site1"},
body: map[string]any{
"id": "site1",
"name": "Team Site",
"mimeType": driveMimeGoogleSite,
"starred": false,
"hasThumbnail": false,
"trashed": false,
},
want: map[string]bool{"starred": false, "hasThumbnail": false},
notWant: []string{"trashed"},
},
{
name: "custom trashed mask",
args: []string{"site1", "--fields", "id,name,trashed"},
body: map[string]any{
"id": "site1",
"name": "Team Site",
"mimeType": driveMimeGoogleSite,
"starred": false,
"hasThumbnail": false,
"trashed": false,
},
want: map[string]bool{"trashed": false},
notWant: []string{"starred", "hasThumbnail"},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
svc, closeSrv := newDriveTestService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.Contains(r.URL.Path, "/files/site1") {
http.NotFound(w, r)
return
}

w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(tc.body)
}))
defer closeSrv()

var stdout bytes.Buffer
ctx := withSitesDriveTestService(newCmdRuntimeJSONOutputContext(t, &stdout, io.Discard), svc)
flags := &RootFlags{Account: "a@b.com"}

if err := runKong(t, &SitesGetCmd{}, tc.args, ctx, flags); err != nil {
t.Fatalf("run: %v", err)
}

var envelope struct {
Site map[string]any `json:"site"`
}
if err := json.Unmarshal(stdout.Bytes(), &envelope); err != nil {
t.Fatalf("invalid JSON: %v\nraw: %s", err, stdout.String())
}

for key, want := range tc.want {
got, ok := envelope.Site[key]
if !ok {
t.Fatalf("missing %q in output: %s", key, stdout.String())
}

if got != want {
t.Fatalf("%q = %v, want %v", key, got, want)
}
}

for _, key := range tc.notWant {
if _, ok := envelope.Site[key]; ok {
t.Fatalf("unexpected %q in output: %s", key, stdout.String())
}
}
})
}
}
Loading