package zitcli
import (
"context"
"errors"
"path/filepath"
"testing"
)
// zit SAYS `check-in 'X' not found`, AND THAT SENTENCE IS THE SIGNAL.
//
// ArchiveTo tells a version nobody wrote apart from a build that failed
// by matching zit's words, because zit spends the same exit status on
// every user error. Prose is a fragile thing to lean on, so this runs the
// REAL binary and asserts both halves of the match are still there: if a
// zit release rewords it, THIS fails — rather than the forge quietly
// going back to answering "the server is at capacity, retry shortly" for
// a version that will never exist.
//
// The forge's half of that pair is worse than a plain wrong answer: a
// client told to retry something that cannot appear retries forever.
func TestArchiveOfAVersionNobodyWroteIsNoVersion(t *testing.T) {
repo := testRepo(t, 1)
c := New(repo)
err := c.ArchiveTo(context.Background(), "tar", "nosuchversion", "",
filepath.Join(t.TempDir(), "out.tgz"), 1<<30)
if err == nil {
t.Fatal("an archive of a version nobody wrote succeeded")
}
if !errors.Is(err, ErrNoVersion) {
t.Errorf("FAIL: an unknown version is not ErrNoVersion: %v\n"+
"the forge answers 'busy' whenever it cannot tell these apart, so a "+
"reworded zit must break HERE and not there", err)
}
// And a real version still works: a classifier that swallowed
// successes would pass the check above and be useless.
good := filepath.Join(t.TempDir(), "ok.tgz")
if err := c.ArchiveTo(context.Background(), "tar", "trunk", "", good, 1<<30); err != nil {
t.Errorf("a real version failed to archive: %v", err)
}
}