Skip to content
quarry Artifact [eff91eeb3c]
Login

Artifact [eff91eeb3c]

Artifact eff91eeb3c177934d873bc2a60d755880d7d53863dd59af204f0c4b3d4ce1c94:


package oltp

import (
	"path/filepath"
	"testing"
)

// An admin's answer to the CI tab's offer survives a reopen, clears when
// withdrawn, and is empty for a repository nobody has answered for —
// which must read as "nobody has said", not as an error.
func TestCIDeclineRoundTrips(t *testing.T) {
	path := filepath.Join(t.TempDir(), "o.db")
	d, err := Open(path)
	if err != nil {
		t.Fatal(err)
	}
	if err := d.AddRepo("orchard", "/srv/orchard", "", "public"); err != nil {
		t.Fatal(err)
	}
	if who, at := d.CIDeclined("orchard"); who != "" || at != "" {
		t.Fatalf("FAIL fresh repository reads declined by %q at %q", who, at)
	}
	t.Log("ok nobody has answered for a fresh repository")

	if err := d.SetCIDeclined("orchard", "dan"); err != nil {
		t.Fatal(err)
	}
	d.Close()
	d, err = Open(path)
	if err != nil {
		t.Fatal(err)
	}
	defer d.Close()
	if who, at := d.CIDeclined("orchard"); who != "dan" || at == "" {
		t.Fatalf("FAIL after reopen: declined by %q at %q, want dan and a time", who, at)
	}
	t.Log("ok the answer survives a reopen, with who and when")

	if err := d.SetCIDeclined("orchard", ""); err != nil {
		t.Fatal(err)
	}
	if who, at := d.CIDeclined("orchard"); who != "" || at != "" {
		t.Fatalf("FAIL withdrawn answer still reads %q at %q", who, at)
	}
	t.Log("ok withdrawing clears both who and when")

	if who, _ := d.CIDeclined("nosuch"); who != "" {
		t.Fatalf("FAIL unknown repository reads declined by %q", who)
	}
	t.Log("ok an unknown repository reads as unanswered")
}