Skip to content
quarry Artifact [2271bccd2a]
Login

Artifact [2271bccd2a]

Artifact 2271bccd2a41501287b9bc758e5520a96023b9b3824eb1d882d5a893db08490e:


package main

import "testing"

// notify accepts lowercase letters, digits, hyphens and underscores in a
// topic key and REJECTS the whole trigger otherwise. quarry's internal
// convention is "repo:<name>" and its repo names allow dots, dashes,
// underscores and uppercase, so the boundary has to translate — running
// the real companion is what surfaced this: a colon key was refused with
// unprocessable_entity and every activity event went nowhere.
func TestRepoTopicKeyIsAcceptableToNotify(t *testing.T) {
	for in, want := range map[string]string{
		"synthetic":         "repo-synthetic",
		"libfossil":         "repo-libfossil",
		"My.Repo":           "repo-my-repo",
		"a_b-c":             "repo-a_b-c",
		"UPPER":             "repo-upper",
		"dots.and.dashes-x": "repo-dots-and-dashes-x",
	} {
		if got := repoTopicKey(in); got != want {
			t.Errorf("repoTopicKey(%q) = %q, want %q", in, got, want)
		}
	}
	// Whatever the input, the result must satisfy notify's rule.
	for _, in := range []string{"Weird!!Name", "with spaces", "tr'ailing..."} {
		got := repoTopicKey(in)
		for _, c := range got {
			if !(c >= 'a' && c <= 'z') && !(c >= '0' && c <= '9') && c != '-' && c != '_' {
				t.Errorf("repoTopicKey(%q) = %q contains %q, which notify refuses", in, got, c)
			}
		}
	}
}