This repository has no description
1package repoident
2
3import (
4 "encoding/json"
5 "testing"
6)
7
8func TestNewRepoDid_RejectsInvalid(t *testing.T) {
9 if _, err := NewRepoDid(""); err == nil {
10 t.Error("NewRepoDid(\"\") err = nil, want error")
11 }
12}
13
14func TestNewRepoDid_AcceptsValid(t *testing.T) {
15 raw := "did:plc:boltless"
16 got, err := NewRepoDid(raw)
17 if err != nil {
18 t.Fatalf("NewRepoDid(%q): %v", raw, err)
19 }
20 if got.String() != raw {
21 t.Errorf("got %q, want %q", got, raw)
22 }
23}
24
25func TestNewOwnerDid_RejectsInvalid(t *testing.T) {
26 if _, err := NewOwnerDid("not-a-did"); err == nil {
27 t.Error("NewOwnerDid(\"not-a-did\") err = nil, want error")
28 }
29}
30
31func TestNewOwnerDid_AcceptsValid(t *testing.T) {
32 raw := "did:plc:akshay"
33 got, err := NewOwnerDid(raw)
34 if err != nil {
35 t.Fatalf("NewOwnerDid(%q): %v", raw, err)
36 }
37 if got.String() != raw {
38 t.Errorf("got %q, want %q", got, raw)
39 }
40}
41
42func TestDidJSONRoundTripsAndValidates(t *testing.T) {
43 var pair struct {
44 Repo RepoDid `json:"repo"`
45 Owner OwnerDid `json:"owner"`
46 }
47 const raw = `{"repo":"did:plc:boltless","owner":"did:plc:akshay"}`
48 if err := json.Unmarshal([]byte(raw), &pair); err != nil {
49 t.Fatalf("Unmarshal: %v", err)
50 }
51 out, err := json.Marshal(pair)
52 if err != nil {
53 t.Fatalf("Marshal: %v", err)
54 }
55 if string(out) != raw {
56 t.Errorf("re-encoded %s, want %s", out, raw)
57 }
58 if err := json.Unmarshal([]byte(`{"repo":"not-a-did","owner":"did:plc:akshay"}`), &pair); err == nil {
59 t.Error("Unmarshal accepted a malformed repoDid")
60 }
61}