示例#1
0
文件: init_test.go 项目: grr89/hrkb
func TestUpdate(t *testing.T) {
	mock := []struct {
		m  Model
		sf Sf
		er bool
	}{
		{&User{Id: 702, Login: "******"}, Sf{"Longin"}, true},
		{&User{Id: 702, Login: "******"}, Sf{"Id"}, true},
		{&User{Id: 702, Login: "******", Active: true}, Sf{"Login"}, false},
		{&User{Id: 702, Login: "******", Active: true}, Sf{"Login", "Active"}, false},
	}
	for k, v := range mock {
		n, err := update(v.m, v.sf)
		if !v.er && err != nil {
			t.Error(err)
		}
		if err == nil && n != 1 {
			t.Error(k, fmt.Sprintf("expected 1 row update. actual %d", n))
		}
		if err == nil && n == 1 {
			u := User{}
			err := find(&u, Sf{"Login"}, W{"Id": v.m.(*User).Id}, W{})
			if err != nil {
				t.Error(err)
			} else if utils.IndexOfStr(v.sf, "Login") != -1 && u.Login != v.m.(*User).Login {
				t.Error(fmt.Sprintf("%d updated to %s", k, u.Login))
			}
		}
	}
}
示例#2
0
文件: base.go 项目: grr89/hrkb
func (c *BaseController) AddAssets(index string, assets []string) {
	ss := c.Data[index].([]string)

	for _, asset := range assets {
		if i := utils.IndexOfStr(ss, asset); i == -1 {
			ss = append(ss, asset)
		}
	}
	c.Data[index] = ss
}