internal/control/repo_test.go

v1.39.0
gitbay/internal/control/repo_test.go history · blame · raw

38 lines · 1165 bytes

 1package control
 2
 3import (
 4	"bytes"
 5	"strings"
 6	"testing"
 7
 8	"gitbay.org/gitbay/internal/protocol"
 9	"gitbay.org/gitbay/internal/store"
10)
11
12// repo show's mirror row must go through the same second-truncation every
13// other timestamp in a view uses, not print the store's raw milliseconds.
14func TestRepoShowMirrorTimeIsTruncatedToTheSecond(t *testing.T) {
15	st, repo, uid := newQueueTestRepo(t)
16	id, err := st.AddMirror(repo.ID, "push", "ssh://example.test/x.git", "", "")
17	if err != nil {
18		t.Fatal(err)
19	}
20	if err := st.SetMirrorResult(id, ""); err != nil {
21		t.Fatal(err)
22	}
23	if _, err := st.DB.Exec("UPDATE mirrors SET last_sync = ? WHERE id = ?", "2026-09-24T15:31:50.839Z", id); err != nil {
24		t.Fatal(err)
25	}
26
27	c, errOut := pruneCtx(st, t.TempDir(), store.User{ID: uid, Username: "alice", IsAdmin: true})
28	if code := runRepoShow(c, []string{repo.Path()}); code != protocol.ExitOK {
29		t.Fatalf("exit %d: %s", code, errOut.String())
30	}
31	out := c.Stdout.(*bytes.Buffer).String()
32	if strings.Contains(out, ".839Z") {
33		t.Errorf("milliseconds leaked: %s", out)
34	}
35	if !strings.Contains(out, "2026-09-24T15:31:50Z") {
36		t.Errorf("no truncated timestamp: %s", out)
37	}
38}