123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package service
- import (
- "context"
- "go-common/app/admin/main/aegis/model/net"
- "testing"
- "encoding/json"
- "github.com/smartystreets/goconvey/convey"
- "go-common/app/admin/main/aegis/model"
- )
- func TestServiceShowDirection(t *testing.T) {
- var (
- c = context.TODO()
- id = int64(1)
- )
- convey.Convey("ShowDirection", t, func(ctx convey.C) {
- r, err := s.ShowDirection(c, id)
- ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(r, convey.ShouldNotBeNil)
- })
- d := r.Direction
- t.Logf("%+v", d)
- oper := &model.NetConfOper{
- OID: d.ID,
- Action: model.LogNetActionUpdate,
- UID: d.UID,
- NetID: d.NetID,
- FlowID: d.FlowID,
- TranID: d.TransitionID,
- Diff: []string{
- model.LogFieldTemp(model.LogFieldDirection, net.DirDirectionDesc[d.Direction], "", false),
- model.LogFieldTemp(model.LogFieldOrder, net.DirOrderDesc[d.Order], "", false),
- model.LogFieldTemp(model.LogFieldGuard, d.Guard, "", false),
- model.LogFieldTemp(model.LogFieldOutput, d.Output, "", false),
- },
- }
- i, _ := json.Marshal(oper)
- t.Logf("%s", i)
- s.sendNetConfLog(c, model.LogTypeDirConf, oper)
- //{"diff":"[指向]为[从节点指向变化]","[顺序]为[]","[输出规则]为[]"}
- })
- }
- func TestServiceGetDirectionList(t *testing.T) {
- var (
- c = context.TODO()
- pm = &net.ListDirectionParam{NetID: 1}
- )
- convey.Convey("GetDirectionList", t, func(ctx convey.C) {
- result, err := s.GetDirectionList(c, pm)
- ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(result, convey.ShouldNotBeNil)
- })
- })
- }
- func TestServicecheckDirectionUnique(t *testing.T) {
- var (
- netID = int64(0)
- FlowID = int64(0)
- transitionID = int64(0)
- direction = int8(0)
- )
- convey.Convey("checkDirectionUnique", t, func(ctx convey.C) {
- err, msg := s.checkDirectionUnique(cntx, netID, FlowID, transitionID, direction)
- ctx.Convey("Then err should be nil.msg should not be nil.", func(ctx convey.C) {
- ctx.So(msg, convey.ShouldNotBeNil)
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestServicecheckDirectionBindAvailable(t *testing.T) {
- var (
- flowID = int64(0)
- transitionID = int64(0)
- )
- convey.Convey("checkDirectionBindAvailable", t, func(ctx convey.C) {
- err := s.checkDirectionBindAvailable(cntx, flowID, transitionID)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestServiceisDirEnable(t *testing.T) {
- var (
- dir = &net.Direction{}
- )
- convey.Convey("isDirEnable", t, func(ctx convey.C) {
- enable := s.isDirEnable(dir)
- ctx.Convey("Then err should be nil.enable should not be nil.", func(ctx convey.C) {
- ctx.So(enable, convey.ShouldNotBeNil)
- })
- })
- }
- func TestServicegetInDirTransitionID(t *testing.T) {
- var (
- flowID = int64(1)
- )
- convey.Convey("fetchFlowNextEnableDirs", t, func(ctx convey.C) {
- dirs, err := s.fetchFlowNextEnableDirs(cntx, flowID)
- ctx.Convey("Then err should be nil.tids,dirList should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(dirs, convey.ShouldNotBeNil)
- })
- })
- }
|