func()

in rocketmq-knative/source/pkg/controller/testing/table.go [214:253]


func (tc *TestCase) VerifyWantPresent(c client.Client) error {
	var errs stateErrors
	for _, wp := range tc.WantPresent {
		o, err := scheme.Scheme.New(wp.GetObjectKind().GroupVersionKind())
		if err != nil {
			errs.errors = append(errs.errors, fmt.Errorf("error creating a copy of %T: %v", wp, err))
		}
		acc, err := meta.Accessor(wp)
		if err != nil {
			errs.errors = append(errs.errors, fmt.Errorf("error getting accessor for %#v %v", wp, err))
		}
		err = c.Get(context.TODO(), client.ObjectKey{Namespace: acc.GetNamespace(), Name: acc.GetName()}, o)
		if err != nil {
			if apierrors.IsNotFound(err) {
				errs.errors = append(errs.errors, fmt.Errorf("want present %T %s/%s, got absent", wp, acc.GetNamespace(), acc.GetName()))
			} else {
				errs.errors = append(errs.errors, fmt.Errorf("error getting %T %s/%s: %v", wp, acc.GetNamespace(), acc.GetName(), err))
			}
		}

		diffOpts := cmp.Options{
			// Ignore TypeMeta, since the objects created by the controller won't have
			// it
			cmpopts.IgnoreTypes(metav1.TypeMeta{}),
		}

		if tc.IgnoreTimes {
			// Ignore VolatileTime fields, since they rarely compare correctly.
			diffOpts = append(diffOpts, cmpopts.IgnoreTypes(apis.VolatileTime{}))
		}

		if diff := cmp.Diff(wp, o, diffOpts...); diff != "" {
			errs.errors = append(errs.errors, fmt.Errorf("Unexpected present %T %s/%s (-want +got):\n%v", wp, acc.GetNamespace(), acc.GetName(), diff))
		}
	}
	if len(errs.errors) > 0 {
		return errs
	}
	return nil
}