-
Notifications
You must be signed in to change notification settings - Fork 2
/
result_test.go
36 lines (31 loc) · 1.06 KB
/
result_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
package dataloader_test
import (
"testing"
"github.com/andy9775/dataloader"
"github.com/stretchr/testify/assert"
)
// ================================================== tests ==================================================
// TestEnsureOKForResult tests getting the result value with a valid key expecting a valid value
func TestEnsureOKForResult(t *testing.T) {
// setup
rmap := dataloader.NewResultMap(2)
key := PrimaryKey(1)
value := dataloader.Result{Result: 1, Err: nil}
rmap.Set(key.String(), value)
// invoke/assert
result, ok := rmap.GetValue(key)
assert.True(t, ok, "Expected valid result to have been found")
assert.Equal(t, result, value, "Expected result")
}
func TestEnsureNotOKForResult(t *testing.T) {
// setup
rmap := dataloader.NewResultMap(2)
key := PrimaryKey(1)
key2 := PrimaryKey(2)
value := dataloader.Result{Result: 1, Err: nil}
rmap.Set(key.String(), value)
// invoke/assert
result, ok := rmap.GetValue(key2)
assert.False(t, ok, "Expected valid result to have been found")
assert.Nil(t, result.Result, "Expected nil result")
}