-
Notifications
You must be signed in to change notification settings - Fork 18
/
create.go
71 lines (59 loc) · 1.71 KB
/
create.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package badgerauthtest
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/gateway-mt/pkg/auth/authdb"
"storj.io/gateway-mt/pkg/auth/badgerauth"
"storj.io/gateway-mt/pkg/auth/badgerauth/pb"
)
// CreateFullRecords creates count of records with random data at node returning
// created records and corresponding replication log entries.
func CreateFullRecords(
ctx *testcontext.Context,
t testing.TB,
node *badgerauth.Node,
count int,
) (
records map[authdb.KeyHash]*authdb.Record,
keys []authdb.KeyHash,
entries []ReplicationLogEntryWithTTL,
) {
records = make(map[authdb.KeyHash]*authdb.Record)
for i := 0; i < count; i++ {
marker := testrand.RandAlphaNumeric(32)
var keyHash authdb.KeyHash
require.NoError(t, keyHash.SetBytes(marker))
// TODO(artur): make expiresAt configurable or random per record.
expiresAt := time.Unix(time.Now().Add(time.Hour).Unix(), 0)
record := &authdb.Record{
SatelliteAddress: string(marker),
MacaroonHead: marker,
EncryptedSecretKey: marker,
EncryptedAccessGrant: marker,
ExpiresAt: &expiresAt,
Public: testrand.Intn(1) == 0,
}
keys = append(keys, keyHash)
records[keyHash] = record
entries = append(entries, ReplicationLogEntryWithTTL{
Entry: badgerauth.ReplicationLogEntry{
ID: node.ID(),
Clock: badgerauth.Clock(i + 1),
KeyHash: keyHash,
State: pb.Record_CREATED,
},
ExpiresAt: expiresAt,
})
Put{
KeyHash: keyHash,
Record: record,
Error: nil,
}.Check(ctx, t, node)
}
return records, keys, entries
}