-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory_test.go
53 lines (38 loc) · 1.29 KB
/
memory_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
var testMemoryProvider = NewInMemoryProvider(map[Hostname]DecentralizedID{
"alice.example.com": "did:plc:example001",
"bob.example.com": "did:plc:example002",
}, map[Domain]bool{
"example.com": true,
})
func TestMemoryProviderHasDecentralizedIdForHandle(t *testing.T) {
handle := Handle{
Domain: "example.com",
Username: "alice",
}
did, err := testMemoryProvider.GetDecentralizedIDForHandle(context.Background(), handle)
assert.Nil(t, err)
assert.Equal(t, did, DecentralizedID("did:plc:example001"))
}
func TestMemoryProviderCanProvideForDomain(t *testing.T) {
expectedToProvide, err := testMemoryProvider.CanProvideForDomain(context.Background(), "example.com")
assert.Nil(t, err)
assert.True(t, expectedToProvide)
expectedNotToProvide, err := testMemoryProvider.CanProvideForDomain(context.Background(), "example.net")
assert.Nil(t, err)
assert.False(t, expectedNotToProvide)
}
func TestMemoryIsHealthyByDefault(t *testing.T) {
healthy, _ := testMemoryProvider.IsHealthy(context.Background())
assert.True(t, healthy)
}
func TestMemoryCanBeSetUnhealthy(t *testing.T) {
testMemoryProvider.SetHealthy(false)
healthy, _ := testMemoryProvider.IsHealthy(context.Background())
assert.False(t, healthy)
}