test: fix utils.AssertEqual
This commit is contained in:
		
							parent
							
								
									c2e36ebe62
								
							
						
					
					
						commit
						c20ec96192
					
				@ -583,7 +583,9 @@ func TestPluck(t *testing.T) {
 | 
				
			|||||||
	if err := DB.Model(User{}).Where("name like ?", "pluck-user%").Order("name desc").Pluck("name", &names2).Error; err != nil {
 | 
						if err := DB.Model(User{}).Where("name like ?", "pluck-user%").Order("name desc").Pluck("name", &names2).Error; err != nil {
 | 
				
			||||||
		t.Errorf("got error when pluck name: %v", err)
 | 
							t.Errorf("got error when pluck name: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	AssertEqual(t, names, sort.Reverse(sort.StringSlice(names2)))
 | 
					
 | 
				
			||||||
 | 
						sort.Slice(names2, func(i, j int) bool { return names2[i] < names2[j] })
 | 
				
			||||||
 | 
						AssertEqual(t, names, names2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var ids []int
 | 
						var ids []int
 | 
				
			||||||
	if err := DB.Model(User{}).Where("name like ?", "pluck-user%").Pluck("id", &ids).Error; err != nil {
 | 
						if err := DB.Model(User{}).Where("name like ?", "pluck-user%").Pluck("id", &ids).Error; err != nil {
 | 
				
			||||||
 | 
				
			|||||||
@ -83,20 +83,22 @@ func AssertEqual(t *testing.T, got, expect interface{}) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if reflect.ValueOf(got).Kind() == reflect.Struct {
 | 
							if reflect.ValueOf(got).Kind() == reflect.Struct {
 | 
				
			||||||
			if reflect.ValueOf(got).NumField() == reflect.ValueOf(expect).NumField() {
 | 
								if reflect.ValueOf(expect).Kind() == reflect.Struct {
 | 
				
			||||||
				exported := false
 | 
									if reflect.ValueOf(got).NumField() == reflect.ValueOf(expect).NumField() {
 | 
				
			||||||
				for i := 0; i < reflect.ValueOf(got).NumField(); i++ {
 | 
										exported := false
 | 
				
			||||||
					if fieldStruct := reflect.ValueOf(got).Type().Field(i); ast.IsExported(fieldStruct.Name) {
 | 
										for i := 0; i < reflect.ValueOf(got).NumField(); i++ {
 | 
				
			||||||
						exported = true
 | 
											if fieldStruct := reflect.ValueOf(got).Type().Field(i); ast.IsExported(fieldStruct.Name) {
 | 
				
			||||||
						field := reflect.ValueOf(got).Field(i)
 | 
												exported = true
 | 
				
			||||||
						t.Run(fieldStruct.Name, func(t *testing.T) {
 | 
												field := reflect.ValueOf(got).Field(i)
 | 
				
			||||||
							AssertEqual(t, field.Interface(), reflect.ValueOf(expect).Field(i).Interface())
 | 
												t.Run(fieldStruct.Name, func(t *testing.T) {
 | 
				
			||||||
						})
 | 
													AssertEqual(t, field.Interface(), reflect.ValueOf(expect).Field(i).Interface())
 | 
				
			||||||
 | 
												})
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if exported {
 | 
										if exported {
 | 
				
			||||||
					return
 | 
											return
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -107,6 +109,9 @@ func AssertEqual(t *testing.T, got, expect interface{}) {
 | 
				
			|||||||
		} else if reflect.ValueOf(expect).Type().ConvertibleTo(reflect.ValueOf(got).Type()) {
 | 
							} else if reflect.ValueOf(expect).Type().ConvertibleTo(reflect.ValueOf(got).Type()) {
 | 
				
			||||||
			expect = reflect.ValueOf(got).Convert(reflect.ValueOf(got).Type()).Interface()
 | 
								expect = reflect.ValueOf(got).Convert(reflect.ValueOf(got).Type()).Interface()
 | 
				
			||||||
			isEqual()
 | 
								isEqual()
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								t.Errorf("%v: expect: %+v, got %+v", utils.FileWithLineNum(), expect, got)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user