tka: reduce boilerplate code in the tests
Updates #cleanup Change-Id: Id69d509f5e470fb5fb50b5c5c4ca61f000389c53 Signed-off-by: Alex Chan <alexc@tailscale.com>
This commit is contained in:
+7
-17
@@ -315,11 +315,6 @@ func TestMarkDescendantAUMs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMarkAncestorIntersectionAUMs(t *testing.T) {
|
||||
fakeState := &State{
|
||||
Keys: []Key{{Kind: Key25519, Votes: 1}},
|
||||
DisablementValues: [][]byte{bytes.Repeat([]byte{1}, 32)},
|
||||
}
|
||||
|
||||
tcs := []struct {
|
||||
name string
|
||||
chain *testChain
|
||||
@@ -333,7 +328,7 @@ func TestMarkAncestorIntersectionAUMs(t *testing.T) {
|
||||
name: "genesis",
|
||||
chain: newTestchain(t, `
|
||||
A
|
||||
A.template = checkpoint`, optTemplate("checkpoint", AUM{MessageKind: AUMCheckpoint, State: fakeState})),
|
||||
A.template = checkpoint`, checkpointTemplate()),
|
||||
initialAncestor: "A",
|
||||
wantAncestor: "A",
|
||||
verdicts: map[string]retainState{
|
||||
@@ -346,7 +341,7 @@ func TestMarkAncestorIntersectionAUMs(t *testing.T) {
|
||||
chain: newTestchain(t, `
|
||||
DEAD -> A -> B -> C
|
||||
A.template = checkpoint
|
||||
B.template = checkpoint`, optTemplate("checkpoint", AUM{MessageKind: AUMCheckpoint, State: fakeState})),
|
||||
B.template = checkpoint`, checkpointTemplate()),
|
||||
initialAncestor: "A",
|
||||
wantAncestor: "A",
|
||||
verdicts: map[string]retainState{
|
||||
@@ -366,7 +361,7 @@ func TestMarkAncestorIntersectionAUMs(t *testing.T) {
|
||||
A.template = checkpoint
|
||||
C.template = checkpoint
|
||||
D.template = checkpoint
|
||||
FORK.hashSeed = 2`, optTemplate("checkpoint", AUM{MessageKind: AUMCheckpoint, State: fakeState})),
|
||||
FORK.hashSeed = 2`, checkpointTemplate()),
|
||||
initialAncestor: "D",
|
||||
wantAncestor: "C",
|
||||
verdicts: map[string]retainState{
|
||||
@@ -387,7 +382,7 @@ func TestMarkAncestorIntersectionAUMs(t *testing.T) {
|
||||
A.template = checkpoint
|
||||
B.template = checkpoint
|
||||
E.template = checkpoint
|
||||
FORK.hashSeed = 2`, optTemplate("checkpoint", AUM{MessageKind: AUMCheckpoint, State: fakeState})),
|
||||
FORK.hashSeed = 2`, checkpointTemplate()),
|
||||
initialAncestor: "E",
|
||||
wantAncestor: "B",
|
||||
verdicts: map[string]retainState{
|
||||
@@ -413,7 +408,7 @@ func TestMarkAncestorIntersectionAUMs(t *testing.T) {
|
||||
D.template = checkpoint
|
||||
E.template = checkpoint
|
||||
FORK.hashSeed = 2
|
||||
DEADFORK.hashSeed = 3`, optTemplate("checkpoint", AUM{MessageKind: AUMCheckpoint, State: fakeState})),
|
||||
DEADFORK.hashSeed = 3`, checkpointTemplate()),
|
||||
initialAncestor: "D",
|
||||
wantAncestor: "C",
|
||||
verdicts: map[string]retainState{
|
||||
@@ -443,7 +438,7 @@ func TestMarkAncestorIntersectionAUMs(t *testing.T) {
|
||||
F.template = checkpoint
|
||||
F1.hashSeed = 2
|
||||
F2.hashSeed = 3
|
||||
F3.hashSeed = 4`, optTemplate("checkpoint", AUM{MessageKind: AUMCheckpoint, State: fakeState})),
|
||||
F3.hashSeed = 4`, checkpointTemplate()),
|
||||
initialAncestor: "F",
|
||||
wantAncestor: "B",
|
||||
verdicts: map[string]retainState{
|
||||
@@ -541,11 +536,6 @@ func cloneMem(src, dst *Mem) {
|
||||
}
|
||||
|
||||
func TestCompact(t *testing.T) {
|
||||
fakeState := &State{
|
||||
Keys: []Key{{Kind: Key25519, Votes: 1}},
|
||||
DisablementValues: [][]byte{bytes.Repeat([]byte{1}, 32)},
|
||||
}
|
||||
|
||||
// A & B are deleted because the new lastActiveAncestor advances beyond them.
|
||||
// OLD is deleted because it does not match retention criteria, and
|
||||
// though it is a descendant of the new lastActiveAncestor (C), it is not a
|
||||
@@ -578,7 +568,7 @@ func TestCompact(t *testing.T) {
|
||||
F1.hashSeed = 1
|
||||
OLD.hashSeed = 2
|
||||
G2.hashSeed = 3
|
||||
`, optTemplate("checkpoint", AUM{MessageKind: AUMCheckpoint, State: fakeState}))
|
||||
`, checkpointTemplate())
|
||||
|
||||
storage := &compactingChonkFake{
|
||||
aumAge: map[AUMHash]time.Time{(c.AUMHashes["F1"]): time.Now()},
|
||||
|
||||
Reference in New Issue
Block a user