示例#1
0
func assertEquivalent(t testing.TB, actual, expected interface{}) bool {
	if actual == nil || expected == nil || reflect.DeepEqual(actual, expected) {
		return true
	}

	actualType := reflect.TypeOf(actual)
	expectedType := reflect.TypeOf(expected)
	if reflect.TypeOf(actual).ConvertibleTo(expectedType) {
		expectedValue := reflect.ValueOf(expected)
		if swag.IsZero(expectedValue) && swag.IsZero(reflect.ValueOf(actual)) {
			return true
		}

		// Attempt comparison after type conversion
		if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) {
			return true
		}
	}

	// Last ditch effort
	if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) {
		return true
	}
	errFmt := "Expected: '%T(%#v)'\nActual:   '%T(%#v)'\n(Should be equivalent)!"
	return assert.Fail(t, errFmt, expected, expected, actual, actual)
}
示例#2
0
func ShouldBeEquivalentTo(actual interface{}, expecteds ...interface{}) string {
	expected := expecteds[0]
	if actual == nil || expected == nil {
		return ""
	}

	if reflect.DeepEqual(expected, actual) {
		return ""
	}

	actualType := reflect.TypeOf(actual)
	expectedType := reflect.TypeOf(expected)
	if reflect.TypeOf(actual).ConvertibleTo(expectedType) {
		expectedValue := reflect.ValueOf(expected)
		if swag.IsZero(expectedValue) && swag.IsZero(reflect.ValueOf(actual)) {
			return ""
		}

		// Attempt comparison after type conversion
		if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) {
			return ""
		}
	}

	// Last ditch effort
	if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) {
		return ""
	}
	errFmt := "Expected: '%T(%#v)'\nActual:   '%T(%#v)'\n(Should be equivalent)!"
	return fmt.Sprintf(errFmt, expected, expected, actual, actual)

}
示例#3
0
文件: task_card.go 项目: vmware/vic
func (m *TaskCard) validateTags(formats strfmt.Registry) error {

	if swag.IsZero(m.Tags) { // not required
		return nil
	}

	iTagsSize := int64(len(m.Tags))

	if err := validate.MaxItems("tags", "body", iTagsSize, 5); err != nil {
		return err
	}

	if err := validate.UniqueItems("tags", "body", m.Tags); err != nil {
		return err
	}

	for i := 0; i < len(m.Tags); i++ {

		if err := validate.RequiredString("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i])); err != nil {
			return err
		}

		if err := validate.MinLength("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i]), 3); err != nil {
			return err
		}

		if err := validate.Pattern("tags"+"."+strconv.Itoa(i), "body", string(m.Tags[i]), `\w[\w- ]+`); err != nil {
			return err
		}

	}

	return nil
}
func (m *RepositoryBuildRequest) validateDockerTags(formats strfmt.Registry) error {

	if swag.IsZero(m.DockerTags) { // not required
		return nil
	}

	iDockerTagsSize := int64(len(m.DockerTags))

	if err := validate.MinItems("docker_tags", "body", iDockerTagsSize, 1); err != nil {
		return err
	}

	if err := validate.UniqueItems("docker_tags", "body", m.DockerTags); err != nil {
		return err
	}

	for i := 0; i < len(m.DockerTags); i++ {

		if err := validate.RequiredString("docker_tags"+"."+strconv.Itoa(i), "body", string(m.DockerTags[i])); err != nil {
			return err
		}

	}

	return nil
}
func (m *CreateAggregatingSubscriptionRequest) validateState(formats strfmt.Registry) error {

	if swag.IsZero(m.State) { // not required
		return nil
	}

	if err := m.validateStateEnum("state", "body", *m.State); err != nil {
		return err
	}

	return nil
}
func (m *CreateAggregatingSubscriptionRequest) validateDurationPeriod(formats strfmt.Registry) error {

	if swag.IsZero(m.DurationPeriod) { // not required
		return nil
	}

	if err := m.validateDurationPeriodEnum("durationPeriod", "body", *m.DurationPeriod); err != nil {
		return err
	}

	return nil
}
示例#7
0
func (m *UserCard) validateAvailableKarma(formats strfmt.Registry) error {

	if swag.IsZero(m.AvailableKarma) { // not required
		return nil
	}

	if err := validate.Maximum("availableKarma", "body", float64(*m.AvailableKarma), 1000, true); err != nil {
		return err
	}

	return nil
}
示例#8
0
func (m *Invoice) validateManagedBy(formats strfmt.Registry) error {

	if swag.IsZero(m.ManagedBy) { // not required
		return nil
	}

	if err := m.validateManagedByEnum("managedBy", "body", *m.ManagedBy); err != nil {
		return err
	}

	return nil
}
示例#9
0
func (m *Version) validateVersion(formats strfmt.Registry) error {

	if swag.IsZero(m.Version) { // not required
		return nil
	}

	if err := validate.MinLength("version", "body", string(m.Version), 1); err != nil {
		return err
	}

	return nil
}
示例#10
0
func (m *TaskAttachmentsAnon) validateDescription(formats strfmt.Registry) error {

	if swag.IsZero(m.Description) { // not required
		return nil
	}

	if err := validate.MinLength("description", "body", string(m.Description), 3); err != nil {
		return err
	}

	return nil
}
示例#11
0
func (m *ProductRatePlan) validateTrialPeriod(formats strfmt.Registry) error {

	if swag.IsZero(m.TrialPeriod) { // not required
		return nil
	}

	if err := m.validateTrialPeriodEnum("trialPeriod", "body", *m.TrialPeriod); err != nil {
		return err
	}

	return nil
}
示例#12
0
func (m *ProductRatePlan) validateRecursionType(formats strfmt.Registry) error {

	if swag.IsZero(m.RecursionType) { // not required
		return nil
	}

	if err := m.validateRecursionTypeEnum("recursionType", "body", *m.RecursionType); err != nil {
		return err
	}

	return nil
}
func (m *CreateSubscriptionRequest) validateBillingEntity(formats strfmt.Registry) error {

	if swag.IsZero(m.BillingEntity) { // not required
		return nil
	}

	if err := m.validateBillingEntityEnum("billingEntity", "body", *m.BillingEntity); err != nil {
		return err
	}

	return nil
}
func (m *CreateSubscriptionRequest) validateType(formats strfmt.Registry) error {

	if swag.IsZero(m.Type) { // not required
		return nil
	}

	if err := m.validateTypeEnum("type", "body", *m.Type); err != nil {
		return err
	}

	return nil
}
示例#15
0
func (m *Order) validateStatus(formats strfmt.Registry) error {

	if swag.IsZero(m.Status) { // not required
		return nil
	}

	if err := m.validateStatusEnum("status", "body", *m.Status); err != nil {
		return err
	}

	return nil
}
示例#16
0
func (m *PaymentMethod) validateBillingEntity(formats strfmt.Registry) error {

	if swag.IsZero(m.BillingEntity) { // not required
		return nil
	}

	if err := m.validateBillingEntityEnum("billingEntity", "body", *m.BillingEntity); err != nil {
		return err
	}

	return nil
}
示例#17
0
func (m *Notification) validateFields(formats strfmt.Registry) error {

	if swag.IsZero(m.Fields) { // not required
		return nil
	}

	if err := validate.Required("fields", "body", m.Fields); err != nil {
		return err
	}

	return nil
}
示例#18
0
func (m *BFError) validateErrorType(formats strfmt.Registry) error {

	if swag.IsZero(m.ErrorType) { // not required
		return nil
	}

	if err := m.validateErrorTypeEnum("errorType", "body", *m.ErrorType); err != nil {
		return err
	}

	return nil
}
示例#19
0
func (m *UserView) validateOrganizations(formats strfmt.Registry) error {

	if swag.IsZero(m.Organizations) { // not required
		return nil
	}

	for i := 0; i < len(m.Organizations); i++ {

	}

	return nil
}
示例#20
0
func (m *VersionData) validateFixes(formats strfmt.Registry) error {

	if swag.IsZero(m.Fixes) { // not required
		return nil
	}

	if err := validate.MinLength("fixes", "body", string(m.Fixes), 1); err != nil {
		return err
	}

	return nil
}
示例#21
0
func (m *Task) validateAttachments(formats strfmt.Registry) error {

	if swag.IsZero(m.Attachments) { // not required
		return nil
	}

	for k := range m.Attachments {

		if swag.IsZero(m.Attachments[k]) { // not required
			continue
		}

		if m.Attachments[k] != nil {

			if err := m.Attachments[k].Validate(formats); err != nil {
				return err
			}
		}

	}

	return nil
}
示例#22
0
func (m *NewPrototype) validateActivatingUser(formats strfmt.Registry) error {

	if swag.IsZero(m.ActivatingUser) { // not required
		return nil
	}

	if m.ActivatingUser != nil {

		if err := m.ActivatingUser.Validate(formats); err != nil {
			return err
		}
	}

	return nil
}
示例#23
0
文件: task_card.go 项目: vmware/vic
func (m *TaskCard) validateEffort(formats strfmt.Registry) error {

	if swag.IsZero(m.Effort) { // not required
		return nil
	}

	if err := validate.Maximum("effort", "body", float64(*m.Effort), 27, false); err != nil {
		return err
	}

	if err := validate.MultipleOf("effort", "body", float64(*m.Effort), 3); err != nil {
		return err
	}

	return nil
}
示例#24
0
func (m *BFError) validateErrorParameters(formats strfmt.Registry) error {

	if swag.IsZero(m.ErrorParameters) { // not required
		return nil
	}

	for i := 0; i < len(m.ErrorParameters); i++ {

		if err := validate.Required("errorParameters"+"."+strconv.Itoa(i), "body", string(m.ErrorParameters[i])); err != nil {
			return err
		}

	}

	return nil
}
示例#25
0
func (m *Member) validateRepositories(formats strfmt.Registry) error {

	if swag.IsZero(m.Repositories) { // not required
		return nil
	}

	for i := 0; i < len(m.Repositories); i++ {

		if err := validate.RequiredString("repositories"+"."+strconv.Itoa(i), "body", string(m.Repositories[i])); err != nil {
			return err
		}

	}

	return nil
}
示例#26
0
func (m *UpdateUser) validateTagExpiration(formats strfmt.Registry) error {

	if swag.IsZero(m.TagExpiration) { // not required
		return nil
	}

	if err := validate.Minimum("tag_expiration", "body", float64(*m.TagExpiration), 0, false); err != nil {
		return err
	}

	if err := validate.Maximum("tag_expiration", "body", float64(*m.TagExpiration), 2.592e+06, false); err != nil {
		return err
	}

	return nil
}
示例#27
0
文件: task_card.go 项目: vmware/vic
func (m *TaskCard) validateKarma(formats strfmt.Registry) error {

	if swag.IsZero(m.Karma) { // not required
		return nil
	}

	if err := validate.Minimum("karma", "body", float64(*m.Karma), 0, true); err != nil {
		return err
	}

	if err := validate.MultipleOf("karma", "body", float64(*m.Karma), 0.5); err != nil {
		return err
	}

	return nil
}
示例#28
0
文件: task_card.go 项目: vmware/vic
func (m *TaskCard) validateSeverity(formats strfmt.Registry) error {

	if swag.IsZero(m.Severity) { // not required
		return nil
	}

	if err := validate.Minimum("severity", "body", float64(*m.Severity), 1, false); err != nil {
		return err
	}

	if err := validate.Maximum("severity", "body", float64(*m.Severity), 5, false); err != nil {
		return err
	}

	return nil
}
func (m *LearningResource) validateScreenshots(formats strfmt.Registry) error {

	if swag.IsZero(m.Screenshots) { // not required
		return nil
	}

	for i := 0; i < len(m.Screenshots); i++ {

		if err := validate.RequiredString("screenshots"+"."+strconv.Itoa(i), "body", string(m.Screenshots[i])); err != nil {
			return err
		}

	}

	return nil
}
示例#30
0
func (m *Recommendations) validateLearningResourceIds(formats strfmt.Registry) error {

	if swag.IsZero(m.LearningResourceIds) { // not required
		return nil
	}

	for i := 0; i < len(m.LearningResourceIds); i++ {

		if err := validate.Required("learning_resource_ids"+"."+strconv.Itoa(i), "body", int64(m.LearningResourceIds[i])); err != nil {
			return err
		}

	}

	return nil
}