-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_test.go
32 lines (25 loc) · 1.08 KB
/
export_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
package hibp
import (
"bytes"
"io"
"testing"
"go.uber.org/mock/gomock"
)
func TestExport(t *testing.T) {
ctrl := gomock.NewController(t)
storageMock := NewMockstorage(ctrl)
storageMock.EXPECT().LoadData("00000").Return(io.NopCloser(bytes.NewReader([]byte("suffix:counter11\r\nsuffix:counter12"))), nil)
storageMock.EXPECT().LoadData("00001").Return(io.NopCloser(bytes.NewReader([]byte("suffix:counter2"))), nil)
storageMock.EXPECT().LoadData("00002").Return(io.NopCloser(bytes.NewReader([]byte("suffix:counter3"))), nil)
buf := bytes.NewBuffer([]byte{})
if err := export(0, 3, storageMock, buf); err != nil {
t.Fatalf("unexpected error: %v", err)
}
// We expect the lines to be prefixed with the range as this is what the response from the official
// HIBP API looks like.
// This has to be the case because `Export` iterates over all ranges; different from `Query` which only
// queries a single range.
if buf.String() != "00000suffix:counter11\r\n00000suffix:counter12\r\n00001suffix:counter2\r\n00002suffix:counter3" {
t.Fatalf("unexpected output: %q", buf.String())
}
}