Browse Source

Fix some tests failures caused by the sorting change and some cuased by previous UpdatePrecedence() change

pull/4275/head
Paul Banks 7 years ago committed by Jack Pearkes
parent
commit
4a54f8f7e3
  1. 13
      agent/consul/state/intention.go
  2. 13
      agent/consul/state/intention_test.go
  3. 4
      agent/structs/intention.go

13
agent/consul/state/intention.go

@ -106,6 +106,11 @@ func (s *Snapshot) Intentions() (structs.Intentions, error) {
var ret structs.Intentions
for wrapped := ixns.Next(); wrapped != nil; wrapped = ixns.Next() {
// Update precedence values for consistency (i.e. the object returned should
// be usable/comparable to the ones returned from Intentions() and Match()
// etc.)
ixn := wrapped.(*structs.Intention)
ixn.UpdatePrecedence()
ret = append(ret, wrapped.(*structs.Intention))
}
@ -142,7 +147,9 @@ func (s *Store) Intentions(ws memdb.WatchSet) (uint64, structs.Intentions, error
var results structs.Intentions
for ixn := iter.Next(); ixn != nil; ixn = iter.Next() {
results = append(results, ixn.(*structs.Intention))
ixnReal := ixn.(*structs.Intention)
ixnReal.UpdatePrecedence()
results = append(results, ixnReal)
}
// Sort by precedence just because that's nicer and probably what most clients
@ -317,7 +324,9 @@ func (s *Store) IntentionMatch(ws memdb.WatchSet, args *structs.IntentionQueryMa
ws.Add(iter.WatchCh())
for ixn := iter.Next(); ixn != nil; ixn = iter.Next() {
ixns = append(ixns, ixn.(*structs.Intention))
ixnReal := ixn.(*structs.Intention)
ixnReal.UpdatePrecedence()
ixns = append(ixns, ixnReal)
}
}

13
agent/consul/state/intention_test.go

@ -273,6 +273,9 @@ func TestStore_IntentionsList(t *testing.T) {
},
},
}
for i := range expected {
expected[i].UpdatePrecedence() // to match what is returned...
}
idx, actual, err := s.Intentions(nil)
assert.NoError(err)
assert.Equal(idx, uint64(2))
@ -496,6 +499,8 @@ func TestStore_Intention_Snapshot_Restore(t *testing.T) {
// Verify the snapshot.
assert.Equal(snap.LastIndex(), uint64(6))
// Expect them sorted in insertion order
expected := structs.Intentions{
&structs.Intention{
ID: ixns[0].ID,
@ -525,6 +530,9 @@ func TestStore_Intention_Snapshot_Restore(t *testing.T) {
},
},
}
for i := range expected {
expected[i].UpdatePrecedence() // to match what is returned...
}
dump, err := snap.Intentions()
assert.NoError(err)
assert.Equal(expected, dump)
@ -538,7 +546,10 @@ func TestStore_Intention_Snapshot_Restore(t *testing.T) {
}
restore.Commit()
// Read the restored values back out and verify that they match.
// Read the restored values back out and verify that they match. Note that
// Intentions are returned precedence sorted unlike the snapshot so we need
// to rearrange the expected slice some.
expected[0], expected[1], expected[2] = expected[1], expected[2], expected[0]
idx, actual, err := s.Intentions(nil)
assert.NoError(err)
assert.Equal(idx, uint64(6))

4
agent/structs/intention.go

@ -217,11 +217,11 @@ func (x *Intention) GetACLPrefix() (string, bool) {
// String returns a human-friendly string for this intention.
func (x *Intention) String() string {
return fmt.Sprintf("%s %s/%s => %s/%s (ID: %s)",
return fmt.Sprintf("%s %s/%s => %s/%s (ID: %s, Precedence: %d)",
strings.ToUpper(string(x.Action)),
x.SourceNS, x.SourceName,
x.DestinationNS, x.DestinationName,
x.ID)
x.ID, x.Precedence)
}
// IntentionAction is the action that the intention represents. This

Loading…
Cancel
Save