func (e *e2e) Diff(ctx context.Context) func(t *testing.T) {
	if err := ctx.Err(); err != nil {
		return func(t *testing.T) { t.Skip(err) }
	}
	return func(t *testing.T) {
		defer e.failed(t)

		absOff := orZero(e.Updates - opLimit)
		t.Logf("offset %d into generated updateOps", absOff)
		for n := range e.vulns()[absOff:] {
			// This does a bunch of checks so that the first operation is
			// compared appropriately.
			i := n + absOff
			prev := uuid.Nil
			if n != 0 {
				prev = e.updateOps[i-1].Ref
			}
			cur := e.updateOps[i].Ref
			t.Logf("comparing %v (index %d) and %v (index %d)", prev, (i-1)-absOff, cur, i-absOff)

			diff, err := e.s.GetUpdateDiff(ctx, prev, cur)
			if err != nil {
				t.Fatalf("received error getting UpdateDiff: %v", err)
			}

			expectSz := opStep
			if n == 0 {
				expectSz = e.Insert
			}
			if l := len(diff.Added); l != expectSz {
				t.Fatalf("got: len == %d, want len == %d", l, expectSz)
			}
			if n == 0 {
				expectSz = 0
			}
			if l := len(diff.Removed); l != expectSz {
				t.Fatalf("got: len == %d, want len == %d", l, expectSz)
			}

			// make sure update operations match generated test values
			if prev != diff.Prev.Ref {
				t.Errorf("want: %v, got: %v", diff.Prev.Ref, prev)
			}
			if cur != diff.Cur.Ref {
				t.Errorf("want: %v, got: %v", diff.Cur.Ref, cur)
			}

			// confirm removed and add vulnerabilities are the ones we expect
			pair := e.calcDiff(i)
			if n == 0 {
				pair[0] = []*claircore.Vulnerability{}
			}
			// I can't figure out how to make a cmp.Option that does this.
			added := make([]*claircore.Vulnerability, len(pair[1]))
			for i := range diff.Added {
				added[i] = &diff.Added[i]
			}
			if want, got := pair[1], added; !cmp.Equal(got, want, vulnCmp) {
				t.Error(cmp.Diff(got, want, vulnCmp))
			}

			removed := make([]*claircore.Vulnerability, len(pair[0]))
			for i := range diff.Removed {
				removed[i] = &diff.Removed[i]
			}
			if want, got := pair[0], removed; !cmp.Equal(want, got, vulnCmp) {
				t.Error(cmp.Diff(want, got, vulnCmp))
			}
		}
		t.Log("ok")
	}
}
// Diff fetches Operation diffs from the database and compares them against
// independently calculated diffs.
Diff fetches Operation diffs from the database and compares them against
independently calculated diffs.
// Diff fetches Operation diffs from the database and compares them against // independently calculated diffs .
func (e *e2e) Diff(ctx context.Context) func(t *testing.T) {
	if err := ctx.Err(); err != nil {
		return func(t *testing.T) { t.Skip(err) }
	}
	return func(t *testing.T) {
		defer e.failed(t)
		absOff := orZero(e.Updates - opLimit)
		t.Logf("offset %d into generated updateOps", absOff)
		for n := range e.vulns()[absOff:] {
			i := n + absOff
			prev := uuid.Nil
			if n != 0 {
				prev = e.updateOps[i-1].Ref
			}
			cur := e.updateOps[i].Ref
			t.Logf("comparing %v (index %d) and %v (index %d)", prev, (i-1)-absOff, cur, i-absOff)
			diff, err := e.s.GetUpdateDiff(ctx, prev, cur)
			if err != nil {
				t.Fatalf("received error getting UpdateDiff: %v", err)
			}
			expectSz := opStep
			if n == 0 {
				expectSz = e.Insert
			}
			if l := len(diff.Added); l != expectSz {
				t.Fatalf("got: len == %d, want len == %d", l, expectSz)
			}
			if n == 0 {
				expectSz = 0
			}
			if l := len(diff.Removed); l != expectSz {
				t.Fatalf("got: len == %d, want len == %d", l, expectSz)
			}
			if prev != diff.Prev.Ref {
				t.Errorf("want: %v, got: %v", diff.Prev.Ref, prev)
			}
			if cur != diff.Cur.Ref {
				t.Errorf("want: %v, got: %v", diff.Cur.Ref, cur)
			}
			pair := e.calcDiff(i)
			if n == 0 {
				pair[0] = []*claircore.Vulnerability{}
			}
			added := make([]*claircore.Vulnerability, len(pair[1]))
			for i := range diff.Added {
				added[i] = &diff.Added[i]
			}
			if want, got := pair[1], added; !cmp.Equal(got, want, vulnCmp) {
				t.Error(cmp.Diff(got, want, vulnCmp))
			}
			removed := make([]*claircore.Vulnerability, len(pair[0]))
			for i := range diff.Removed {
				removed[i] = &diff.Removed[i]
			}
			if want, got := pair[0], removed; !cmp.Equal(want, got, vulnCmp) {
				t.Error(cmp.Diff(want, got, vulnCmp))
			}
		}
		t.Log("ok")
	}
}
func ( e * e2e ) Diff ( ctx context . Context ) func ( t * testing . T ) { if err := ctx . Err ( ) ; err != nil { return func ( t * testing . T ) { t . Skip ( err ) } } return func ( t * testing . T ) { defer e . failed ( t ) absOff := orZero ( e . Updates - opLimit ) t . Logf ( " " , absOff ) for n := range e . vulns ( ) [ absOff : ] { i := n + absOff prev := uuid . Nil if n != 0 { prev = e . updateOps [ i - 1 ] . Ref } cur := e . updateOps [ i ] . Ref t . Logf ( " " , prev , ( i - 1 ) - absOff , cur , i - absOff ) diff , err := e . s . GetUpdateDiff ( ctx , prev , cur ) if err != nil { t . Fatalf ( " " , err ) } expectSz := opStep if n == 0 { expectSz = e . Insert } if l := len ( diff . Added ) ; l != expectSz { t . Fatalf ( " " , l , expectSz ) } if n == 0 { expectSz = 0 } if l := len ( diff . Removed ) ; l != expectSz { t . Fatalf ( " " , l , expectSz ) } if prev != diff . Prev . Ref { t . Errorf ( " " , diff . Prev . Ref , prev ) } if cur != diff . Cur . Ref { t . Errorf ( " " , diff . Cur . Ref , cur ) } pair := e . calcDiff ( i ) if n == 0 { pair [ 0 ] = [ ] * claircore . Vulnerability { } } added := make ( [ ] * claircore . Vulnerability , len ( pair [ 1 ] ) ) for i := range diff . Added { added [ i ] = & diff . Added [ i ] } if want , got := pair [ 1 ] , added ; ! cmp . Equal ( got , want , vulnCmp ) { t . Error ( cmp . Diff ( got , want , vulnCmp ) ) } removed := make ( [ ] * claircore . Vulnerability , len ( pair [ 0 ] ) ) for i := range diff . Removed { removed [ i ] = & diff . Removed [ i ] } if want , got := pair [ 0 ] , removed ; ! cmp . Equal ( want , got , vulnCmp ) { t . Error ( cmp . Diff ( want , got , vulnCmp ) ) } } t . Log ( " " ) } }
Diff fetches Operation diffs from the database and compares them against
independently calculated diffs.
Diff fetches Operation diffs from the database and compares them against independently calculated diffs .
// This does a bunch of checks so that the first operation is // compared appropriately. // make sure update operations match generated test values // confirm removed and add vulnerabilities are the ones we expect // I can't figure out how to make a cmp.Option that does this.