github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/tests/integrations/resource_test.go (about) 1 package integrations 2 3 import ( 4 "bytes" 5 "os" 6 "path" 7 "testing" 8 9 . "github.com/onsi/gomega" 10 11 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/tests/clients/applet_mgr" 12 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/tests/requires" 13 "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/transformer" 14 "github.com/machinefi/w3bstream/pkg/modules/applet" 15 "github.com/machinefi/w3bstream/pkg/types" 16 ) 17 18 func TestResourceAPIs(t *testing.T) { 19 var ( 20 ctx = requires.Context() 21 client = requires.AuthClient() 22 projectName = "test_resource_project" 23 24 appletID types.SFID 25 resourceID types.SFID 26 ) 27 28 t.Logf("random a project name: %s, use this name create a project and an applet.", projectName) 29 30 { 31 req := &applet_mgr.CreateProject{} 32 req.CreateReq.Name = projectName 33 34 _, _, err := client.CreateProject(req) 35 if err != nil { 36 panic(err) 37 } 38 } 39 40 { 41 cwd, err := os.Getwd() 42 filename := path.Join(cwd, "../testdata/log.wasm") 43 appletName := "testApplet" 44 wasmName := "test.log" 45 46 req := &applet_mgr.CreateApplet{ProjectName: projectName} 47 req.CreateReq.File = transformer.MustNewFileHeader("file", filename, bytes.NewBuffer(code)) 48 req.CreateReq.Info = applet.Info{ 49 AppletName: appletName, 50 WasmName: wasmName, 51 } 52 53 rsp, _, err := client.CreateApplet(req) 54 if err != nil { 55 panic(err) 56 } 57 appletID = rsp.AppletID 58 } 59 60 { 61 applet, err := applet.GetBySFID(ctx, appletID) 62 if err != nil { 63 panic(err) 64 } 65 resourceID = applet.ResourceID 66 } 67 68 defer func() { 69 req := &applet_mgr.RemoveProject{ProjectName: projectName} 70 _, err := client.RemoveProject(req) 71 if err != nil { 72 panic(err) 73 } 74 }() 75 76 t.Logf("start test resource api.") 77 78 t.Run("Resource", func(t *testing.T) { 79 t.Run("#GetResuorce", func(t *testing.T) { 80 t.Run("#Success", func(t *testing.T) { 81 82 // get resource 83 { 84 req := &applet_mgr.DownloadResource{ResourceID: resourceID} 85 _, _, err := client.DownloadResource(req) 86 NewWithT(t).Expect(err).To(BeNil()) 87 } 88 89 // get list strategies 90 { 91 req := &applet_mgr.ListResources{} 92 _, _, err := client.ListResources(req) 93 NewWithT(t).Expect(err).To(BeNil()) 94 } 95 96 // remove resource 97 { 98 req := &applet_mgr.RemoveResource{ResourceID: resourceID} 99 _, err := client.RemoveResource(req) 100 NewWithT(t).Expect(err).To(BeNil()) 101 } 102 }) 103 }) 104 }) 105 106 }