Skip to content
quarry Artifact [423b4582cd]
Login

Artifact [423b4582cd]

Artifact 423b4582cd34869418f77329a4246121b00922d1d968942c2b5d7bc3b6edb211:


package zitcli

import "testing"

// The strings here are REAL zit output, captured by serving one copy of
// a store and pulling into another. They are the contract between zit's
// wording and quarry's mirror scheduler, and this test is what turns a
// wording change from a silent stale mirror into a build failure.
func TestPullChangedReadsRealZitOutput(t *testing.T) {
	for _, tc := range []struct {
		name string
		out  string
		want bool
	}{
		{"nothing new", "already up to date\n", false},
		{"artifacts arrived", "received 2 artifacts in 2 rounds\n", true},
		{"a larger fetch", "received 1409 artifacts in 7 rounds\n", true},
	} {
		got, err := pullChanged([]byte(tc.out))
		if err != nil {
			t.Errorf("%s: %v", tc.name, err)
			continue
		}
		if got != tc.want {
			t.Errorf("%s: changed = %v, want %v", tc.name, got, tc.want)
		}
	}
}

// An unrecognized result must be an ERROR, never a quiet false. A quiet
// false is a mirror that reports success, never re-indexes, and shows
// green on the fleet page while drifting arbitrarily far from upstream.
func TestPullChangedRefusesToGuess(t *testing.T) {
	for _, out := range []string{
		"",
		"fetched 3 artifacts",    // a plausible future rewording
		"synchronized with peer", // ditto
		"nothing to do",          // ditto
	} {
		if _, err := pullChanged([]byte(out)); err == nil {
			t.Errorf("pullChanged(%q) returned no error — an unknown result was guessed at", out)
		}
	}
}