Skip to content
quarry Artifact [de31ea8f3d]
Login

Artifact [de31ea8f3d]

Artifact de31ea8f3dd141690368eb21b83d14e1ee0303a742d74789f7b9dc618471f660:


package zitcli

import (
	"bytes"
	"strings"
	"testing"
)

// A Git import's store appears only when it completes, so its progress
// is zit's own count, read off standard error as the import runs; the
// output still reaches the caller whole.
func TestGitImportProgressFollowsZitsCount(t *testing.T) {
	var diag bytes.Buffer
	p := &importProgress{dest: "/tmp/x", w: &diag}
	if _, _, ok := GitImportProgress("/tmp/x"); ok {
		t.Fatal("FAIL: progress before zit counted anything")
	}
	for _, line := range []string{
		"import-git: exporting\n",
		"import-git: 192/563 commits (34%), 84/s\n",
		"import-git: 320/563 commits (56%), 50/s\nimport-git: 512/563 commits (90%), 80/s\n",
	} {
		p.Write([]byte(line))
	}
	if done, total, ok := GitImportProgress("/tmp/x"); !ok || done != 512 || total != 563 {
		t.Errorf("FAIL: progress = %d/%d (%v), want the latest count, 512/563", done, total, ok)
	}
	if !strings.Contains(diag.String(), "192/563") || !strings.HasPrefix(diag.String(), "import-git: exporting") {
		t.Error("FAIL: the import's output did not reach the caller whole")
	}
	gitImports.Delete("/tmp/x")
}