Skip to content
quarry Artifact [8021029d41]
Login

Artifact [8021029d41]

Artifact 8021029d411e4c006df3096dce2bd5f2c369392146362c7e6e130343792564bc:


package api

import (
	"path/filepath"
	"strings"
	"testing"

	"craftdesign.group/quarry/internal/oltp"
)

// A mirror of kind git is pulled with the Git pull, never zit pull, and
// is refused the unversioned-file import (#358).
func TestAGitMirrorPullsWithGit(t *testing.T) {
	db, err := oltp.Open(filepath.Join(t.TempDir(), "o.db"))
	if err != nil {
		t.Fatal(err)
	}
	t.Cleanup(func() { db.Close() })
	if err := db.AddRepo("r", t.TempDir(), "", oltp.Public); err != nil {
		t.Fatal(err)
	}
	if err := db.SetMirror("r", "https://github.com/a/b", oltp.MinMirrorInterval); err != nil {
		t.Fatal(err)
	}
	if err := db.SetMirrorGit("r"); err != nil {
		t.Fatal(err)
	}
	var fossil, git int
	d := Deps{Mirrors: oltpMirrors{db}, Repos: NewRepos(map[string]*Repo{"r": {
		Mirror:    func(string) (bool, error) { fossil++; return false, nil },
		MirrorGit: func(string) (bool, error) { git++; return false, nil },
	}})}
	m, ok, err := d.Mirrors.MirrorFor("r")
	if err != nil || !ok || !m.Git {
		t.Fatalf("FAIL: the mirror reads back as %+v %v %v", m, ok, err)
	}
	if _, err := d.PullMirror(m); err != nil {
		t.Fatal(err)
	}
	if git != 1 || fossil != 0 {
		t.Errorf("FAIL: git pulls %d, zit pulls %d", git, fossil)
	}
	if why := d.uvBlocked("r"); !strings.Contains(why, "Git") {
		t.Errorf("FAIL: the uv import is not refused for a Git mirror: %q", why)
	}
}