ident_test.go

 1package ident
 2
 3import "testing"
 4
 5func TestRepoDID(t *testing.T) {
 6	d := RepoDID("git.kilimanjaro.io", "sovrn")
 7	if d != "did:web:git.kilimanjaro.io:sovrn" {
 8		t.Fatal(d)
 9	}
10	h, r, err := ParseRepoDID(d)
11	if err != nil || h != "git.kilimanjaro.io" || r != "sovrn" {
12		t.Fatal(h, r, err)
13	}
14	if h, r, _ := ParseRepoDID(RepoDID("localhost:8080", "x")); h != "localhost:8080" || r != "x" {
15		t.Error(h, r)
16	}
17	for _, bad := range []string{"did:plc:abc", "did:web:host", "did:web:host:a:b", "did:web::x"} {
18		if _, _, err := ParseRepoDID(bad); err == nil {
19			t.Errorf("%s accepted", bad)
20		}
21	}
22}