application config group handler test

This commit is contained in:
yangk 2020-09-22 18:18:31 +08:00
parent 078d061196
commit 1cc956d201
5 changed files with 2388 additions and 983 deletions

View File

@ -0,0 +1,97 @@
package handler
import (
"testing"
"github.com/go-playground/assert/v2"
"github.com/golang/mock/gomock"
"github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/db"
daomock "github.com/goodrain/rainbond/db/dao"
dbmodel "github.com/goodrain/rainbond/db/model"
)
func TestCreateAppConfigGroup(t *testing.T) {
appID := "appID1"
serviceID := "sid1"
configName := "configname1"
serviceConfigGroupReq := &dbmodel.ServiceConfigGroup{
AppID: appID,
ConfigGroupName: configName,
ServiceID: serviceID,
}
configReq := &dbmodel.ApplicationConfigGroup{
AppID: appID,
ConfigGroupName: configName,
DeployType: "env",
}
var configItems []model.ConfigItem
it1 := model.ConfigItem{
AppID: appID,
ConfigGroupName: configName,
ItemKey: "key1",
ItemValue: "value1",
}
configItems = append(configItems, it1)
it2 := model.ConfigItem{
AppID: appID,
ConfigGroupName: configName,
ItemKey: "key2",
ItemValue: "value2",
}
configItems = append(configItems, it2)
testReq := &model.ApplicationConfigGroup{
AppID: appID,
ConfigGroupName: configName,
DeployType: "env",
ServiceIDs: []string{"sid1"},
ConfigItems: configItems,
}
var serviceResult []dbmodel.ServiceIDAndNameResult
sReslt := dbmodel.ServiceIDAndNameResult{
ServiceID: "sid1",
ServiceName: "sid1_name",
}
serviceResult = append(serviceResult, sReslt)
applicationConfigGroup := &dbmodel.ApplicationConfigGroup{
AppID: testReq.AppID,
ConfigGroupName: testReq.ConfigGroupName,
DeployType: testReq.DeployType,
}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
manager := db.NewMockManager(ctrl)
db.SetTestManager(manager)
serviceConfigGroupDao := daomock.NewMockServiceConfigGroupDao(ctrl)
serviceConfigGroupDao.EXPECT().AddModel(serviceConfigGroupReq).Return(nil).AnyTimes()
manager.EXPECT().ServiceConfigGroupDao().Return(serviceConfigGroupDao).AnyTimes()
configItemDao := daomock.NewMockConfigItemDao(ctrl)
configItemDao.EXPECT().AddModel(gomock.Any()).Return(nil).AnyTimes()
manager.EXPECT().ConfigItemDao().Return(configItemDao).AnyTimes()
applicationConfigDao := daomock.NewMockApplicationConfigDao(ctrl)
applicationConfigDao.EXPECT().AddModel(configReq).Return(nil)
applicationConfigDao.EXPECT().GetConfigByID(appID, configName).Return(applicationConfigGroup, nil)
manager.EXPECT().ApplicationConfigDao().Return(applicationConfigDao).AnyTimes()
tenantServiceDao := daomock.NewMockTenantServiceDao(ctrl)
tenantServiceDao.EXPECT().GetServicesIDAndNameByAppID(appID).Return(serviceResult)
manager.EXPECT().TenantServiceDao().Return(tenantServiceDao)
appAction := NewApplicationHandler()
resp, _ := appAction.AddConfigGroup(appID, testReq)
assert.Equal(t, applicationConfigGroup.AppID, testReq.AppID)
for _, serviceResp := range resp.Services {
for _, expService := range serviceResult {
assert.Equal(t, expService.ServiceName, serviceResp.ServiceName)
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1
go.mod
View File

@ -34,6 +34,7 @@ require (
github.com/go-chi/render v1.0.1
github.com/go-kit/kit v0.10.0
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/go-playground/assert/v2 v2.0.1
github.com/go-sql-driver/mysql v1.5.0
github.com/gogo/protobuf v1.3.1
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b

1
go.sum
View File

@ -540,6 +540,7 @@ github.com/go-openapi/validate v0.19.3/go.mod h1:90Vh6jjkTn+OT1Eefm0ZixWNFjhtOH7
github.com/go-openapi/validate v0.19.8 h1:YFzsdWIDfVuLvIOF+ZmKjVg1MbPJ1QgY9PihMwei1ys=
github.com/go-openapi/validate v0.19.8/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85nY1c2z52x1Gk4=
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=