Skip to content
quarry Artifact [3a0ffdf199]
Login

Artifact [3a0ffdf199]

Artifact 3a0ffdf19911d2b16f3a49bc3300949ae3fe822fb003b090ad29b04a357b0079:


package web

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

// TestQuickStartRecipesCloneFirst: every recipe on an empty repository's
// page starts with a clone. A repository made elsewhere carries another
// project code and its push is refused, so a recipe that starts any
// other way promises something the forge does not do.
func TestQuickStartRecipesCloneFirst(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))
	}
	for _, m := range pres {
		first := strings.SplitN(strings.TrimSpace(m[2]), "\n", 2)[0]
		if !strings.HasPrefix(first, "zit clone {{.CloneURL}}") {
			t.Errorf("FAIL: recipe %s starts with %q, not a clone of this repository", m[1], first)
		}
		if !strings.Contains(m[2], "zit push") {
			t.Errorf("FAIL: recipe %s never pushes", m[1])
		}
	}
	if strings.Count(quickStartSource, "<pre") != len(pres) {
		t.Errorf("FAIL: a recipe on the page has no qs- hook")
	}
	t.Log("ok")
}