File: registry_test.go

package info (click to toggle)
golang-github-joomcode-errorx 1.2.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 280 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 712 bytes parent folder | download
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
package errorx

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestRegistry(t *testing.T) {
	s := &testSubscriber{}
	RegisterTypeSubscriber(s)

	require.Contains(t, s.namespaces, CommonErrors.Key())
	require.Contains(t, s.types, AssertionFailed)

	ns := NewNamespace("TestRegistry")
	require.Contains(t, s.namespaces, ns.Key())

	errorType := ns.NewType("Test")
	require.Contains(t, s.types, errorType)
}

type testSubscriber struct {
	types      []*Type
	namespaces []NamespaceKey
}

func (s *testSubscriber) OnNamespaceCreated(namespace Namespace) {
	s.namespaces = append(s.namespaces, namespace.Key())
}

func (s *testSubscriber) OnTypeCreated(t *Type) {
	s.types = append(s.types, t)
}