github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/tests/integrations/publisher_test.go (about) 1 package integrations 2 3 import ( 4 "fmt" 5 "testing" 6 7 . "github.com/onsi/gomega" 8 9 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/tests/clients/applet_mgr" 10 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/tests/requires" 11 confid "github.com/machinefi/w3bstream/pkg/depends/conf/id" 12 "github.com/machinefi/w3bstream/pkg/modules/publisher" 13 "github.com/machinefi/w3bstream/pkg/types" 14 ) 15 16 func TestPublisherAPIs(t *testing.T) { 17 var ( 18 ctx = requires.Context() 19 client = requires.AuthClient() 20 projectName = "test_publisher_project" 21 publisherName = "testpublisher" 22 publisherKey = confid.MustSFIDGeneratorFromContext(ctx).MustGenSFID().String() 23 24 publisherID types.SFID 25 ) 26 27 t.Logf("random a project name: %s, use this name create a project.", projectName) 28 29 { 30 req := &applet_mgr.CreateProject{} 31 req.CreateReq.Name = projectName 32 33 _, _, err := client.CreateProject(req) 34 if err != nil { 35 panic(err) 36 } 37 } 38 39 defer func() { 40 req := &applet_mgr.RemoveProject{ProjectName: projectName} 41 _, err := client.RemoveProject(req) 42 if err != nil { 43 panic(err) 44 } 45 }() 46 47 t.Logf("random a publisher name and publisehr key: %s - %s, then create a pulbisher .", 48 publisherName, publisherKey) 49 50 t.Run("Publisher", func(t *testing.T) { 51 t.Run("#CreatePublisher", func(t *testing.T) { 52 t.Run("#Success", func(t *testing.T) { 53 54 // create publisher 55 { 56 req := &applet_mgr.CreatePublisher{ 57 ProjectName: projectName, 58 CreateReq: publisher.CreateReq{ 59 Name: publisherName, 60 Key: publisherKey, 61 }, 62 } 63 64 rsp, _, err := client.CreatePublisher(req) 65 NewWithT(t).Expect(err).To(BeNil()) 66 NewWithT(t).Expect(rsp.Name).To(Equal(publisherName)) 67 publisherID = rsp.PublisherID 68 } 69 70 // get publisher 71 { 72 req := &applet_mgr.GetPublisher{PublisherID: publisherID} 73 rsp, _, err := client.GetPublisher(req) 74 NewWithT(t).Expect(err).To(BeNil()) 75 NewWithT(t).Expect(rsp.Name).To(Equal(publisherName)) 76 } 77 78 // update publisher 79 { 80 updateName := "updatepublisher" 81 req := &applet_mgr.UpdatePublisher{ 82 ProjectName: projectName, 83 PublisherID: publisherID, 84 UpdateReq: publisher.UpdateReq{ 85 Name: updateName, 86 Key: publisherKey, 87 }, 88 } 89 _, err := client.UpdatePublisher(req) 90 NewWithT(t).Expect(err).To(BeNil()) 91 } 92 93 // remove publisher 94 { 95 req := &applet_mgr.RemovePublisher{PublisherID: publisherID} 96 _, err := client.RemovePublisher(req) 97 NewWithT(t).Expect(err).To(BeNil()) 98 } 99 }) 100 }) 101 }) 102 103 t.Run("BatchPublisher", func(t *testing.T) { 104 t.Run("#CreatePublishers", func(t *testing.T) { 105 t.Run("#Success", func(t *testing.T) { 106 107 // prepare data 108 num := 5 109 { 110 for i := 0; i < num; i++ { 111 pubName := fmt.Sprintf("testpublisher%d", i) 112 req := &applet_mgr.CreatePublisher{ 113 ProjectName: projectName, 114 CreateReq: publisher.CreateReq{ 115 Name: pubName, 116 Key: confid.MustSFIDGeneratorFromContext(ctx).MustGenSFID().String(), 117 }, 118 } 119 rsp, _, err := client.CreatePublisher(req) 120 NewWithT(t).Expect(err).To(BeNil()) 121 NewWithT(t).Expect(rsp.Name).To(Equal(pubName)) 122 } 123 } 124 125 // get list publisher 126 { 127 req := &applet_mgr.ListPublisher{ProjectName: projectName} 128 rsp, _, err := client.ListPublisher(req) 129 NewWithT(t).Expect(err).To(BeNil()) 130 NewWithT(t).Expect(num).To(Equal(int(rsp.Total))) 131 } 132 133 // remove batch publisher 134 { 135 req := &applet_mgr.BatchRemovePublisher{ProjectName: projectName} 136 _, err := client.BatchRemovePublisher(req) 137 NewWithT(t).Expect(err).To(BeNil()) 138 } 139 140 }) 141 }) 142 }) 143 }