github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/trafficlimit/traffic_limit_test.go (about) 1 package trafficlimit 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/golang/mock/gomock" 8 . "github.com/onsi/gomega" 9 10 confid "github.com/machinefi/w3bstream/pkg/depends/conf/id" 11 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 12 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder" 13 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/mock" 14 "github.com/machinefi/w3bstream/pkg/depends/x/contextx" 15 "github.com/machinefi/w3bstream/pkg/errors/status" 16 "github.com/machinefi/w3bstream/pkg/models" 17 "github.com/machinefi/w3bstream/pkg/types" 18 ) 19 20 func TestTrafficLimit(t *testing.T) { 21 ctrl := gomock.NewController(t) 22 defer ctrl.Finish() 23 24 var ( 25 db = mock.NewMockDBExecutor(ctrl) 26 idg = confid.MustNewSFIDGenerator() 27 ctx = contextx.WithContextCompose( 28 types.WithMgrDBExecutorContext(db), 29 confid.WithSFIDGeneratorContext(idg), 30 types.WithProjectContext(&models.Project{ 31 RelProject: models.RelProject{ProjectID: idg.MustGenSFID()}, 32 ProjectName: models.ProjectName{Name: "test_project_for_traffic_limit_unit_test"}, 33 }), 34 )(context.Background()) 35 ) 36 37 t.Run("Get", func(t *testing.T) { 38 t.Run("#Success", func(t *testing.T) { 39 db.EXPECT().T(gomock.Any()).Return(&builder.Table{}).Times(1) 40 db.EXPECT().QueryAndScan(gomock.Any(), gomock.Any()).Return(nil).Times(1) 41 42 // Get 43 { 44 _, err := GetBySFID(ctx, idg.MustGenSFID()) 45 NewWithT(t).Expect(err).To(BeNil()) 46 } 47 }) 48 49 t.Run("#TrafficLimitNotFound", func(t *testing.T) { 50 db.EXPECT().T(gomock.Any()).Return(&builder.Table{}).Times(1) 51 db.EXPECT().QueryAndScan(gomock.Any(), gomock.Any()).Return(sqlx.NewSqlError(sqlx.SqlErrTypeNotFound, "")).Times(1) 52 53 // Get 54 { 55 _, err := GetBySFID(ctx, 1) 56 NewWithT(t).Expect(err).To(Equal(status.TrafficLimitNotFound)) 57 } 58 }) 59 }) 60 61 // t.Run("List", func(t *testing.T) { 62 // t.Run("Success", func(t *testing.T) { 63 // db.EXPECT().T(gomock.Any()).Return(&builder.Table{}).Times(6) 64 // db.EXPECT().QueryAndScan(gomock.Any(), gomock.Any()).Return(nil).Times(6) 65 66 // // List 67 // { 68 // _, err := List(ctx, &ListReq{}) 69 // NewWithT(t).Expect(err).To(BeNil()) 70 // } 71 72 // // ListByCond 73 // { 74 // _, err := ListByCond(ctx, &CondArgs{}) 75 // NewWithT(t).Expect(err).To(BeNil()) 76 // } 77 78 // { 79 // _, err := ListDetail(ctx, &ListReq{}) 80 // NewWithT(t).Expect(err).To(BeNil()) 81 // } 82 // }) 83 // }) 84 }