示例#1
0
func TestDefaultPK(t *testing.T) {
	fields, err := crud.GetFieldsOf(Foo{})
	assert.Nil(t, err)

	crud.SetDefaultPK(fields)
	assert.Equal(t, len(fields), 4)
	assert.Equal(t, fields[0].Name, "Id")
	assert.Equal(t, fields[0].SQL.Name, "id")
	assert.Equal(t, fields[0].SQL.Type, "int")
	assert.Equal(t, fields[0].SQL.AutoIncrement, 1)
	assert.True(t, fields[0].SQL.IsRequired)
	assert.True(t, fields[0].SQL.IsPrimaryKey)
	assert.Equal(t, fields[1].Name, "APIKey")
	assert.Equal(t, fields[1].SQL.Name, "api_key")
	assert.Equal(t, fields[1].SQL.Type, "varchar")
	assert.Equal(t, fields[2].Name, "YOLO")
	assert.Equal(t, fields[2].SQL.Name, "yolo")
	assert.Equal(t, fields[2].SQL.Type, "tinyint")
	assert.Equal(t, fields[3].Name, "Beast")
	assert.Equal(t, fields[3].SQL.Name, "beast")
	assert.Equal(t, fields[3].SQL.Type, "varchar")
}
示例#2
0
func TestSetDefaultPK(t *testing.T) {
	fields, err := crud.GetFieldsOf(Foo{})
	crud.SetDefaultPK(fields)
	assert.Nil(t, err)
	assert.True(t, fields[0].SQL.IsPrimaryKey)
}