123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- package dao
- import (
- "go-common/app/admin/ep/melloi/model"
- "testing"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoAddScene(t *testing.T) {
- convey.Convey("AddScene", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- SceneName: "CMTest001",
- UserName: "chenmeng",
- Department: "test",
- Project: "ep",
- APP: "melloi",
- IsDraft: 1,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- sceneId, err := d.AddScene(scene)
- convCtx.Convey("Then err should be nil.sceneId should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(sceneId, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryDraft(t *testing.T) {
- convey.Convey("QueryDraft", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- UserName: "chenmeng",
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryDraft(scene)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUpdateScene(t *testing.T) {
- convey.Convey("UpdateScene", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- ID: 66,
- }
- scriptIDList = []int{1831, 1832, 1833, 1834, 1835}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- fusing, err := d.UpdateScene(scene, scriptIDList)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(fusing, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSaveScene(t *testing.T) {
- convey.Convey("SaveScene", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- ID: 66,
- IsDraft: 0,
- SceneType: 2,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.SaveScene(scene)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoSaveOrderAuto(t *testing.T) {
- convey.Convey("SaveOrder", t, func(convCtx convey.C) {
- var (
- reqList = []*model.GroupOrder{
- {
- GroupID: 1,
- RunOrder: 2,
- ID: 980,
- TestName: "cm-test",
- },
- {
- GroupID: 1,
- RunOrder: 1,
- ID: 973,
- TestName: "status111",
- },
- }
- sceneAuto = &model.Scene{
- SceneType: 1,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.SaveOrder(reqList, sceneAuto)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoSaveOrderGroup(t *testing.T) {
- convey.Convey("SaveOrder", t, func(convCtx convey.C) {
- var (
- reqList = []*model.GroupOrder{
- {
- GroupID: 1,
- RunOrder: 2,
- ID: 980,
- TestName: "cm-test",
- },
- {
- GroupID: 1,
- RunOrder: 1,
- ID: 973,
- TestName: "status111",
- },
- }
- sceneGroup = &model.Scene{
- SceneType: 2,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.SaveOrder(reqList, sceneGroup)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoQueryGroupId(t *testing.T) {
- convey.Convey("QueryGroupId", t, func(convCtx convey.C) {
- var (
- script = &model.Script{
- ID: 1568,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, groupId, err := d.QueryGroupId(script)
- convCtx.Convey("Then err should be nil.res,groupId should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(groupId, convey.ShouldNotBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryRelation(t *testing.T) {
- convey.Convey("QueryRelation", t, func(convCtx convey.C) {
- var (
- groupId = 11
- script = &model.Script{
- ID: 1568,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryRelation(groupId, script)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryAPI(t *testing.T) {
- convey.Convey("QueryAPI", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- ID: 325,
- SceneType: 1,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryAPI(scene)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoDeleteAPI(t *testing.T) {
- d.DB.Model(&model.Script{}).Where("ID = 1568").Update("active", 1)
- convey.Convey("DeleteAPI", t, func(convCtx convey.C) {
- var (
- script = &model.Script{
- ID: 1568,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.DeleteAPI(script)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoAddConfig(t *testing.T) {
- d.DB.Exec("update script set threads_sum = 10, load_time = 10, ready_time = 10 where scene_id = 325 and group_id = 1")
- convey.Convey("AddConfig", t, func(convCtx convey.C) {
- var (
- script = &model.Script{
- ThreadsSum: 120,
- LoadTime: 300,
- ReadyTime: 10,
- SceneID: 325,
- GroupID: 1,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.AddConfig(script)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoQueryTree(t *testing.T) {
- convey.Convey("QueryTree", t, func(convCtx convey.C) {
- var (
- script = &model.Script{
- SceneID: 325,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryTree(script)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryScenesByPage(t *testing.T) {
- convey.Convey("QueryScenesByPage", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- Department: "test",
- Project: "ep",
- APP: "melloi",
- SceneName: "场景压测cmtest01",
- UserName: "chenmeng",
- }
- pn = int32(1)
- ps = int32(20)
- treeNodes = []string{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- qsr, err := d.QueryScenesByPage(scene, pn, ps, treeNodes)
- convCtx.Convey("Then err should be nil.qsr should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(qsr, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryScenesByPageWhiteName(t *testing.T) {
- convey.Convey("QueryScenesByPageWhiteName", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- Department: "test",
- Project: "ep",
- APP: "melloi",
- SceneName: "场景压测cmtest01",
- UserName: "chenmeng",
- }
- pn = int32(1)
- ps = int32(20)
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- qsr, err := d.QueryScenesByPageWhiteName(scene, pn, ps)
- convCtx.Convey("Then err should be nil.qsr should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(qsr, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryScenes(t *testing.T) {
- convey.Convey("QueryScenes", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- UserName: "chenmeng",
- }
- pn = 1
- ps = 10
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- scenes, err := d.QueryScenes(scene, pn, ps)
- convCtx.Convey("Then err should be nil.scenes should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(scenes, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryExistAPI(t *testing.T) {
- convey.Convey("QueryExistAPI", t, func(convCtx convey.C) {
- var (
- script = &model.Script{
- SceneID: 325,
- }
- pageNum = int32(1)
- pageSize = int32(10)
- sceneId = int(325)
- treeNodes = []string{}
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryExistAPI(script, pageNum, pageSize, sceneId, treeNodes)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryGroup(t *testing.T) {
- convey.Convey("QueryGroup", t, func(convCtx convey.C) {
- var (
- sceneId = 325
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryGroup(sceneId)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryPreview(t *testing.T) {
- convey.Convey("QueryPreview", t, func(convCtx convey.C) {
- var (
- sceneId = 325
- groupId = 1
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryPreview(sceneId, groupId)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoQueryUsefulParams(t *testing.T) {
- convey.Convey("QueryUsefulParams", t, func(convCtx convey.C) {
- var (
- sceneId = 325
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryUsefulParams(sceneId)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUpdateBindScene(t *testing.T) {
- convey.Convey("UpdateBindScene", t, func(convCtx convey.C) {
- var (
- bindScene = &model.BindScene{
- SceneID: 325,
- ID: "2000",
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.UpdateBindScene(bindScene)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoQueryDrawRelation(t *testing.T) {
- convey.Convey("QueryDrawRelation", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- ID: 980,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryDrawRelation(scene)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoDeleteDraft(t *testing.T) {
- convey.Convey("DeleteDraft", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- UserName: "chenmeng",
- ID: 980,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.DeleteDraft(scene)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoQueryConfig(t *testing.T) {
- convey.Convey("QueryConfig", t, func(convCtx convey.C) {
- var (
- script = &model.Script{
- SceneID: 325,
- GroupID: 1,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- res, err := d.QueryConfig(script)
- convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- convCtx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoDeleteScene(t *testing.T) {
- convey.Convey("DeleteScene", t, func(convCtx convey.C) {
- var (
- scene = &model.Scene{
- ID: 325,
- }
- )
- convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
- err := d.DeleteScene(scene)
- convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
- convCtx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
|