-
Notifications
You must be signed in to change notification settings - Fork 3
/
options_test.go
55 lines (41 loc) · 1.38 KB
/
options_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
54
55
package raft
import (
"testing"
"github.com/stretchr/testify/require"
)
// TestWithLog checks that the log option only accepts non-nil logs.
func TestWithLog(t *testing.T) {
options := &options{}
// Test nil input
require.Error(t, WithLog(nil)(options))
// Test valid input
log := &persistentLog{}
require.NoError(t, WithLog(log)(options))
}
// TestWithStateStorage checks that the state storage option only accepts non-nil state storage.
func TestWithStateStorage(t *testing.T) {
options := &options{}
// Test nil input
require.Error(t, WithStateStorage(nil)(options))
// Test valid input
stateStore := &persistentStateStorage{}
require.NoError(t, WithStateStorage(stateStore)(options))
}
// TestWithSnapshotStorage checks that the snapshot storage option only accepts non-nil snapshot storage.
func TestWithSnapshotStorage(t *testing.T) {
options := &options{}
// Test nil input
require.Error(t, WithSnapshotStorage(nil)(options))
// Test valid input
snapshotStore := &persistentSnapshotStorage{}
require.NoError(t, WithSnapshotStorage(snapshotStore)(options))
}
// TestWithTransport checks that the transport option only accepts non-nil transport.
func TestWithTransport(t *testing.T) {
options := &options{}
// Test nil input
require.Error(t, WithTransport(nil)(options))
// Test valid input
transport := &transport{}
require.NoError(t, WithTransport(transport)(options))
}