settings-1 final fixes: digests CLI tests derive every expectation
The header is matched against textChannelsHeader, the status-on line is built from bah's real marker time, and the unverifiable-marker line from the real marker error, so a copy edit cannot break or panic them (Astra r1 #7).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+23
−7
channels_digests_test.go+23 −7
diff --git a/channels_digests_test.go b/channels_digests_test.go| index 5d940c111..2750d6d17 100644 |
| --- a/channels_digests_test.go |
| +++ b/channels_digests_test.go |
| @@ -9,6 +9,7 @@ import ( |
| "net/http" |
| "net/http/httptest" |
| "os" |
| + "slices" |
| "strings" |
| "testing" |
| "time" |
| @@ -112,13 +113,20 @@ func TestChannelsVerbAPIModeDigestsColumn(t *testing.T) { |
| runChannels([]string{"-app", "titogo", "-account", apiTestAccount}) |
| rows := map[string]string{} |
| + header := false |
| + wantHeader := strings.Fields(strings.ReplaceAll(textChannelsHeader, "\t", " ")) |
| for _, line := range strings.Split(buf.String(), "\n") { |
| - if f := strings.Fields(line); len(f) > 0 { |
| + f := strings.Fields(line) |
| + if slices.Equal(f, wantHeader) { |
| + header = true |
| + continue |
| + } |
| + if len(f) > 0 { |
| rows[f[0]] = strings.TrimSpace(line) |
| } |
| } |
| - if !strings.Contains(rows["CHANNEL"], "DIGESTS") { |
| - t.Fatalf("header = %q", rows["CHANNEL"]) |
| + if !header { |
| + t.Fatalf("no %q header in:\n%s", textChannelsHeader, buf.String()) |
| } |
| for ch, want := range map[string]string{"stable": textStateYes, "beta": textStateStraggler, "edge": textStateNo} { |
| if !strings.HasSuffix(rows[ch], want) { |
| @@ -328,17 +336,25 @@ func TestChannelsDigestsDirectStore(t *testing.T) { |
| t.Fatal("on did not write the marker") |
| } |
| // bah has no apps at all: on, straight after turning it on. |
| - if m, _ := release.ReadDigestMarker(ctx, s, pub, "bah"); m == nil || !strings.Contains(out, "pointer digests: on for bah since ") { |
| - t.Fatalf("an account with no apps does not read on:\n%s", out) |
| + bah, err := release.ReadDigestMarker(ctx, s, pub, "bah") |
| + if err != nil || bah == nil { |
| + t.Fatalf("on did not write bah's marker: %v %v", bah, err) |
| + } |
| + if want := fmt.Sprintf(textStatusOn, "bah", bah.At.UTC().Format(time.RFC3339)); !strings.Contains(out, want) { |
| + t.Fatalf("an account with no apps does not read on (want %q):\n%s", want, out) |
| } |
| // An unverifiable marker is unknown, and the none-left line stays away. |
| if _, err := s.Put(ctx, release.PointerDigestsKey("bai"), []byte("junk"), ""); err != nil { |
| t.Fatal(err) |
| } |
| + _, merr := release.ReadDigestMarker(ctx, s, pub, "bai") |
| + if merr == nil { |
| + t.Fatal("control: the junk marker verified") |
| + } |
| out = runDigests(t, "--account-id", "bai") |
| - if !strings.HasPrefix(strings.Split(out, "\n")[0], fmt.Sprintf(textStatusError, "bai", "")[:len("pointer digests: unknown for bai")]) { |
| - t.Fatalf("unverifiable marker:\n%s", out) |
| + if want := fmt.Sprintf(textStatusError, "bai", merr); !strings.Contains(out, want) { |
| + t.Fatalf("unverifiable marker (want %q):\n%s", want, out) |
| } |
| if strings.Contains(out, textStatusNoneLeft) || strings.Contains(out, fmt.Sprintf(textStatusOff, "bai")) { |
| t.Fatalf("unverifiable marker read as off or done:\n%s", out) |