Skip to content
quarry Artifact [7dd2a44b5d]
Login

Artifact [7dd2a44b5d]

Artifact 7dd2a44b5d25f2817423907ba01bbe2576764c4e0842ea92b6608b3b648c3bb4:


package web

import (
	"regexp"
	"strings"
	"testing"
)

// TestQuickStartRecipesStartRight: the first recipe on an empty
// repository's page pushes an existing repository to it (it adopts that
// project's code and history), and every other recipe starts with a
// clone of this repository, which is what gives a new local copy its
// project code. Every recipe ends in a push, and the first contact is
// never a pull or a sync.
func TestQuickStartRecipesStartRight(t *testing.T) {
	pres := regexp.MustCompile(`(?s)<pre data-hook="(qs-[a-z]+)">(.*?)</pre>`).FindAllStringSubmatch(quickStartSource, -1)
	if len(pres) < 2 {
		t.Fatalf("FAIL: want at least two recipes, got %d", len(pres))
	}
	if pres[0][1] != "qs-push" {
		t.Errorf("FAIL: the first recipe is %s, not the push of an existing repository", pres[0][1])
	}
	for _, m := range pres {
		lines := strings.Split(strings.TrimSpace(m[2]), "\n")
		clones := strings.HasPrefix(lines[0], "zit clone {{.CloneURL}}")
		if m[1] == "qs-push" {
			clones = false
			if !strings.Contains(m[2], "zit remote {{.CloneURL}}") {
				t.Errorf("FAIL: recipe %s never names this repository as the remote", m[1])
			}
		} else if !clones {
			t.Errorf("FAIL: recipe %s starts with %q, not a clone of this repository", m[1], lines[0])
		}
		if !strings.HasPrefix(lines[len(lines)-1], "zit push") {
			t.Errorf("FAIL: recipe %s does not end in a push", m[1])
		}
		for _, l := range lines {
			if strings.HasPrefix(l, "zit pull") || strings.HasPrefix(l, "zit sync") {
				t.Errorf("FAIL: recipe %s contacts the repository with %q before pushing", m[1], l)
			}
		}
	}
	if strings.Count(quickStartSource, "<pre") != len(pres) {
		t.Errorf("FAIL: a recipe on the page has no qs- hook")
	}
	if !strings.Contains(quickStartSource, `data-hook="qs-first"`) {
		t.Errorf("FAIL: the page does not say the first contact must be a push")
	}
	if !t.Failed() {
		t.Log("ok")
	}
}