[FIX] bug: reflect.Value.Set using unaddressable value

This commit is contained in:
GLYASAI 2018-11-26 20:37:50 +08:00
parent a2cb4cce94
commit 6c2fc4eb2b
7 changed files with 72 additions and 42 deletions

View File

@ -48,7 +48,7 @@ type TenantDao interface {
GetTenantByUUIDIsExist(uuid string) bool GetTenantByUUIDIsExist(uuid string) bool
} }
//TenantDao tenant dao //AppDao tenant dao
type AppDao interface { type AppDao interface {
Dao Dao
GetByEventId(eventID string) (*model.AppStatus, error) GetByEventId(eventID string) (*model.AppStatus, error)
@ -351,16 +351,16 @@ type RuleExtensionDao interface {
DeleteRuleExtensionByRuleID(ruleID string) error DeleteRuleExtensionByRuleID(ruleID string) error
} }
// HttpRuleDao - // HTTPRuleDao -
type HttpRuleDao interface { type HTTPRuleDao interface {
Dao Dao
GetHttpRuleByID(id string) (*model.HTTPRule, error) GetHttpRuleByID(id string) (*model.HTTPRule, error)
GetHttpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) ([]*model.HTTPRule, error) GetHttpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) ([]*model.HTTPRule, error)
DeleteHttpRuleByID(id string) error DeleteHttpRuleByID(id string) error
} }
// TcpRuleDao - // TCPRuleDao -
type TcpRuleDao interface { type TCPRuleDao interface {
Dao Dao
GetTcpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) ([]*model.TCPRule, error) GetTcpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) ([]*model.TCPRule, error)
GetTcpRuleByID(id string) (*model.TCPRule, error) GetTcpRuleByID(id string) (*model.TCPRule, error)

View File

@ -2911,7 +2911,7 @@ func (_mr *_MockRuleExtensionDaoRecorder) DeleteRuleExtensionByRuleID(arg0 inter
return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteRuleExtensionByRuleID", arg0) return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteRuleExtensionByRuleID", arg0)
} }
// Mock of HttpRuleDao interface // Mock of HTTPRuleDao interface
type MockHttpRuleDao struct { type MockHttpRuleDao struct {
ctrl *gomock.Controller ctrl *gomock.Controller
recorder *_MockHttpRuleDaoRecorder recorder *_MockHttpRuleDaoRecorder
@ -2995,7 +2995,7 @@ func (_mr *_MockHttpRuleDaoRecorder) DeleteHttpRuleByID(arg0 interface{}) *gomoc
return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteHttpRuleByID", arg0) return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteHttpRuleByID", arg0)
} }
// Mock of TcpRuleDao interface // Mock of TCPRuleDao interface
type MockTcpRuleDao struct { type MockTcpRuleDao struct {
ctrl *gomock.Controller ctrl *gomock.Controller
recorder *_MockTcpRuleDaoRecorder recorder *_MockTcpRuleDaoRecorder

View File

@ -98,10 +98,10 @@ type Manager interface {
CertificateDaoTransactions(db *gorm.DB) dao.CertificateDao CertificateDaoTransactions(db *gorm.DB) dao.CertificateDao
RuleExtensionDao() dao.RuleExtensionDao RuleExtensionDao() dao.RuleExtensionDao
RuleExtensionDaoTransactions(db *gorm.DB) dao.RuleExtensionDao RuleExtensionDaoTransactions(db *gorm.DB) dao.RuleExtensionDao
HttpRuleDao() dao.HttpRuleDao HttpRuleDao() dao.HTTPRuleDao
HttpRuleDaoTransactions(db *gorm.DB) dao.HttpRuleDao HttpRuleDaoTransactions(db *gorm.DB) dao.HTTPRuleDao
TcpRuleDao() dao.TcpRuleDao TcpRuleDao() dao.TCPRuleDao
TcpRuleDaoTransactions(db *gorm.DB) dao.TcpRuleDao TcpRuleDaoTransactions(db *gorm.DB) dao.TCPRuleDao
} }
var defaultManager Manager var defaultManager Manager

View File

@ -610,19 +610,19 @@ func (_mr *_MockManagerRecorder) RuleExtensionDaoTransactions(arg0 interface{})
return _mr.mock.ctrl.RecordCall(_mr.mock, "RuleExtensionDaoTransactions", arg0) return _mr.mock.ctrl.RecordCall(_mr.mock, "RuleExtensionDaoTransactions", arg0)
} }
func (_m *MockManager) HttpRuleDao() dao.HttpRuleDao { func (_m *MockManager) HttpRuleDao() dao.HTTPRuleDao {
ret := _m.ctrl.Call(_m, "HttpRuleDao") ret := _m.ctrl.Call(_m, "HTTPRuleDao")
ret0, _ := ret[0].(dao.HttpRuleDao) ret0, _ := ret[0].(dao.HTTPRuleDao)
return ret0 return ret0
} }
func (_mr *_MockManagerRecorder) HttpRuleDao() *gomock.Call { func (_mr *_MockManagerRecorder) HttpRuleDao() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "HttpRuleDao") return _mr.mock.ctrl.RecordCall(_mr.mock, "HTTPRuleDao")
} }
func (_m *MockManager) HttpRuleDaoTransactions(db *gorm.DB) dao.HttpRuleDao { func (_m *MockManager) HttpRuleDaoTransactions(db *gorm.DB) dao.HTTPRuleDao {
ret := _m.ctrl.Call(_m, "HttpRuleDaoTransactions", db) ret := _m.ctrl.Call(_m, "HttpRuleDaoTransactions", db)
ret0, _ := ret[0].(dao.HttpRuleDao) ret0, _ := ret[0].(dao.HTTPRuleDao)
return ret0 return ret0
} }
@ -630,19 +630,19 @@ func (_mr *_MockManagerRecorder) HttpRuleDaoTransactions(arg0 interface{}) *gomo
return _mr.mock.ctrl.RecordCall(_mr.mock, "HttpRuleDaoTransactions", arg0) return _mr.mock.ctrl.RecordCall(_mr.mock, "HttpRuleDaoTransactions", arg0)
} }
func (_m *MockManager) TcpRuleDao() dao.TcpRuleDao { func (_m *MockManager) TcpRuleDao() dao.TCPRuleDao {
ret := _m.ctrl.Call(_m, "TcpRuleDao") ret := _m.ctrl.Call(_m, "TCPRuleDao")
ret0, _ := ret[0].(dao.TcpRuleDao) ret0, _ := ret[0].(dao.TCPRuleDao)
return ret0 return ret0
} }
func (_mr *_MockManagerRecorder) TcpRuleDao() *gomock.Call { func (_mr *_MockManagerRecorder) TcpRuleDao() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TcpRuleDao") return _mr.mock.ctrl.RecordCall(_mr.mock, "TCPRuleDao")
} }
func (_m *MockManager) TcpRuleDaoTransactions(db *gorm.DB) dao.TcpRuleDao { func (_m *MockManager) TcpRuleDaoTransactions(db *gorm.DB) dao.TCPRuleDao {
ret := _m.ctrl.Call(_m, "TcpRuleDaoTransactions", db) ret := _m.ctrl.Call(_m, "TcpRuleDaoTransactions", db)
ret0, _ := ret[0].(dao.TcpRuleDao) ret0, _ := ret[0].(dao.TCPRuleDao)
return ret0 return ret0
} }

View File

@ -196,32 +196,62 @@ func TestCockroachDBDeleteService(t *testing.T) {
} }
} }
func TestCockroachDBSaveDeployInfo(t *testing.T) { //func TestCockroachDBSaveDeployInfo(t *testing.T) {
// if err := CreateManager(dbconfig.Config{
// MysqlConnectionInfo: "postgresql://root@localhost:5432/region?sslmode=disable",
// DBType: "cockroachdb",
// }); err != nil {
// t.Fatal(err)
// }
// err := GetManager().K8sDeployReplicationDao().AddModel(&model.K8sDeployReplication{
// TenantID: "asdasd",
// ServiceID: "asdasdasdasd",
// ReplicationID: "asdasdadsasdasdasd",
// ReplicationType: model.TypeReplicationController,
// })
// if err != nil {
// t.Fatal(err)
// }
//}
//func TestCockroachDBDeleteDeployInfo(t *testing.T) {
// if err := CreateManager(dbconfig.Config{
// MysqlConnectionInfo: "postgresql://root@localhost:5432/region?sslmode=disable",
// DBType: "cockroachdb",
// }); err != nil {
// t.Fatal(err)
// }
//err := GetManager().K8sDeployReplicationDao().DeleteK8sDeployReplication("asdasdadsasdasdasd")
//if err != nil {
// t.Fatal(err)
//}
//}
func TestGetHttpRuleByServiceIDAndContainerPort(t *testing.T) {
if err := CreateManager(dbconfig.Config{ if err := CreateManager(dbconfig.Config{
MysqlConnectionInfo: "postgresql://root@localhost:5432/region?sslmode=disable", MysqlConnectionInfo: "admin:admin@tcp(127.0.0.1:3306)/region",
DBType: "cockroachdb", DBType: "mysql",
}); err != nil { }); err != nil {
t.Fatal(err) t.Fatal(err)
} }
err := GetManager().K8sDeployReplicationDao().AddModel(&model.K8sDeployReplication{
TenantID: "asdasd", _, err := GetManager().HttpRuleDao().GetHttpRuleByServiceIDAndContainerPort(
ServiceID: "asdasdasdasd", "43eaae441859eda35b02075d37d83581", 10001)
ReplicationID: "asdasdadsasdasdasd",
ReplicationType: model.TypeReplicationController,
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestCockroachDBDeleteDeployInfo(t *testing.T) { func TestGetTcpRuleByServiceIDAndContainerPort(t *testing.T) {
if err := CreateManager(dbconfig.Config{ if err := CreateManager(dbconfig.Config{
MysqlConnectionInfo: "postgresql://root@localhost:5432/region?sslmode=disable", MysqlConnectionInfo: "admin:admin@tcp(127.0.0.1:3306)/region",
DBType: "cockroachdb", DBType: "mysql",
}); err != nil { }); err != nil {
t.Fatal(err) t.Fatal(err)
} }
err := GetManager().K8sDeployReplicationDao().DeleteK8sDeployReplication("asdasdadsasdasdasd")
_, err := GetManager().TcpRuleDao().GetTcpRuleByServiceIDAndContainerPort(
"43eaae441859eda35b02075d37d83581", 10001)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -166,7 +166,7 @@ func (h *HttpRuleDaoImpl) GetHttpRuleByServiceIDAndContainerPort(serviceID strin
containerPort int) ([]*model.HTTPRule, error) { containerPort int) ([]*model.HTTPRule, error) {
var httpRule []*model.HTTPRule var httpRule []*model.HTTPRule
if err := h.DB.Where("service_id = ? and container_port = ?", serviceID, if err := h.DB.Where("service_id = ? and container_port = ?", serviceID,
containerPort).Find(httpRule).Error; err != nil { containerPort).Find(&httpRule).Error; err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return httpRule, nil return httpRule, nil
} }
@ -221,7 +221,7 @@ func (s *TcpRuleDaoTmpl) GetTcpRuleByServiceIDAndContainerPort(serviceID string,
containerPort int) ([]*model.TCPRule, error) { containerPort int) ([]*model.TCPRule, error) {
var result []*model.TCPRule var result []*model.TCPRule
if err := s.DB.Where("service_id = ? and container_port = ?", serviceID, if err := s.DB.Where("service_id = ? and container_port = ?", serviceID,
containerPort).Find(result).Error; err != nil { containerPort).Find(&result).Error; err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return result, nil return result, nil
} }

View File

@ -413,25 +413,25 @@ func (m *Manager) RuleExtensionDaoTransactions(db *gorm.DB) dao.RuleExtensionDao
} }
} }
func (m *Manager) HttpRuleDao() dao.HttpRuleDao { func (m *Manager) HttpRuleDao() dao.HTTPRuleDao {
return &mysqldao.HttpRuleDaoImpl{ return &mysqldao.HttpRuleDaoImpl{
DB: m.db, DB: m.db,
} }
} }
func (m *Manager) HttpRuleDaoTransactions(db *gorm.DB) dao.HttpRuleDao { func (m *Manager) HttpRuleDaoTransactions(db *gorm.DB) dao.HTTPRuleDao {
return &mysqldao.HttpRuleDaoImpl{ return &mysqldao.HttpRuleDaoImpl{
DB: db, DB: db,
} }
} }
func (m *Manager) TcpRuleDao() dao.TcpRuleDao { func (m *Manager) TcpRuleDao() dao.TCPRuleDao {
return &mysqldao.TcpRuleDaoTmpl{ return &mysqldao.TcpRuleDaoTmpl{
DB: m.db, DB: m.db,
} }
} }
func (m *Manager) TcpRuleDaoTransactions(db *gorm.DB) dao.TcpRuleDao { func (m *Manager) TcpRuleDaoTransactions(db *gorm.DB) dao.TCPRuleDao {
return &mysqldao.TcpRuleDaoTmpl{ return &mysqldao.TcpRuleDaoTmpl{
DB: db, DB: db,
} }