Skip to content
quarry Artifact [b799332d5a]
Login

Artifact [b799332d5a]

Artifact b799332d5a9cb8041429ea639f6fd9c6f8568a99957c9a0420f114b47c8316a5:


package oltp

import (
	"strings"
	"testing"
)

// A dot separates subject tokens wherever a repository's events travel,
// so a name may hold dots only between non-empty parts: "a." and "a..b"
// would put an empty token in a subject that no exact filter can name,
// and a repository nobody can address cannot be deleted either.
func TestARepositoryNameHasNoEmptyDotSegment(t *testing.T) {
	for _, name := range []string{"a", "a.b", "a-b_c.d.e9", "A1", strings.Repeat("x", 64)} {
		if !RepoName.MatchString(name) {
			t.Errorf("%q refused", name)
		}
	}
	for _, name := range []string{"", ".a", "a.", "a..b", "a.b.", "-a", "a/b", "a b", "a*", "a>", strings.Repeat("x", 65)} {
		if RepoName.MatchString(name) {
			t.Errorf("%q accepted", name)
		}
	}
}

// A double underscore joins a group to a pool's name, so no repository
// may hold one: a name with it is refused, at creation as in a flag.
func TestARepositoryNameHoldsNoDoubleUnderscore(t *testing.T) {
	for _, name := range []string{"a__b", "__a", "a__", "a___b"} {
		if RepoName.MatchString(name) {
			t.Errorf("FAIL: %q accepted", name)
		}
	}
	if !RepoName.MatchString("a_b") {
		t.Errorf("FAIL: a single underscore was refused")
	}
	d := testDB(t)
	if err := d.AddRepo("pi__c", t.TempDir(), "", "public"); err == nil {
		t.Errorf("FAIL: AddRepo accepted a name with a double underscore")
	}
	if !t.Failed() {
		t.Log("ok")
	}
}