forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine_common.go
104 lines (94 loc) · 2.82 KB
/
engine_common.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package test
import (
"sort"
"testing"
"github.com/keybase/client/go/libkb"
"github.com/keybase/kbfs/libkbfs"
"github.com/keybase/kbfs/tlf"
)
func setBlockSizes(t testing.TB, config libkbfs.Config, blockSize, blockChangeSize int64) {
// Set the block sizes, if any
if blockSize > 0 || blockChangeSize > 0 {
if blockSize == 0 {
blockSize = 512 * 1024
}
if blockChangeSize < 0 {
t.Fatal("Can't handle negative blockChangeSize")
}
if blockChangeSize == 0 {
blockChangeSize = 8 * 1024
}
bsplit, err := libkbfs.NewBlockSplitterSimple(blockSize,
uint64(blockChangeSize), config.Codec())
if err != nil {
t.Fatalf("Couldn't make block splitter for block size %d,"+
" blockChangeSize %d: %v", blockSize, blockChangeSize, err)
}
config.SetBlockSplitter(bsplit)
}
}
func maybeSetBw(t testing.TB, config libkbfs.Config, bwKBps int) {
if bwKBps > 0 {
config.SetBlockOps(libkbfs.NewBlockOpsConstrained(
config.BlockOps(), bwKBps))
// Looks like we're testing big transfers, so let's do
// background flushes.
config.SetDoBackgroundFlushes(true)
}
}
func makeTeams(t testing.TB, config libkbfs.Config, e Engine, teams teamMap,
users map[libkb.NormalizedUsername]User) {
teamNames := make([]libkb.NormalizedUsername, 0, len(teams))
for name := range teams {
teamNames = append(teamNames, name)
}
sort.Slice(teamNames, func(i, j int) bool {
return string(teamNames[i]) < string(teamNames[j])
}) // make sure root names go first.
infos := libkbfs.AddEmptyTeamsForTestOrBust(t, config, teamNames...)
for i, name := range teamNames {
members := teams[name]
tid := infos[i].TID
for _, w := range members.writers {
libkbfs.AddTeamWriterForTestOrBust(t, config, tid,
e.GetUID(users[w]))
}
for _, r := range members.readers {
libkbfs.AddTeamReaderForTestOrBust(t, config, tid,
e.GetUID(users[r]))
}
}
}
func makeImplicitTeams(t testing.TB, config libkbfs.Config, e Engine,
implicitTeams teamMap, users map[libkb.NormalizedUsername]User) {
if len(implicitTeams) > 0 {
err := libkbfs.EnableImplicitTeamsForTest(config)
if err != nil {
t.Fatal(err)
}
}
counter := byte(1)
for name, members := range implicitTeams {
ty := tlf.Private
if len(members.readers) == 1 &&
members.readers[0] == libkb.NormalizedUsername("public") {
ty = tlf.Public
}
teamID := libkbfs.AddImplicitTeamForTestOrBust(
t, config, name.String(), "", counter, ty)
counter++
for _, w := range members.writers {
libkbfs.AddTeamWriterForTestOrBust(t, config, teamID,
e.GetUID(users[w]))
}
if ty == tlf.Private {
for _, r := range members.readers {
libkbfs.AddTeamReaderForTestOrBust(t, config, teamID,
e.GetUID(users[r]))
}
}
}
}