github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/tests/integrations/project_test.go (about)

     1  package integrations
     2  
     3  import (
     4  	"strings"
     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  	"github.com/machinefi/w3bstream/pkg/depends/kit/statusx"
    12  	"github.com/machinefi/w3bstream/pkg/enums"
    13  	"github.com/machinefi/w3bstream/pkg/errors/status"
    14  	"github.com/machinefi/w3bstream/pkg/modules/config"
    15  	"github.com/machinefi/w3bstream/pkg/types"
    16  )
    17  
    18  func TestProjectAPIs(t *testing.T) {
    19  	var (
    20  		ctx         = requires.Context()
    21  		client      = requires.AuthClient()
    22  		projectName = "test_project"
    23  		projectID   types.SFID
    24  	)
    25  
    26  	t.Logf("random a project name: %s", projectName)
    27  
    28  	t.Run("Project", func(t *testing.T) {
    29  		t.Run("#CreateProject", func(t *testing.T) {
    30  			t.Run("#Success", func(t *testing.T) {
    31  
    32  				// create project without user defined config(database/env)
    33  				{
    34  					req := &applet_mgr.CreateProject{}
    35  					req.CreateReq.Name = projectName
    36  
    37  					rsp, _, err := client.CreateProject(req)
    38  
    39  					NewWithT(t).Expect(err).To(BeNil())
    40  					NewWithT(t).Expect(rsp.Name).To(Equal(projectName))
    41  					projectID = rsp.ProjectID
    42  				}
    43  
    44  				// check project default config
    45  				{
    46  					req := &applet_mgr.GetProjectSchema{ProjectName: projectName}
    47  					rsp, _, err := client.GetProjectSchema(req)
    48  
    49  					NewWithT(t).Expect(err).To(BeNil())
    50  					NewWithT(t).Expect(rsp.ConfigType()).
    51  						To(Equal(enums.CONFIG_TYPE__PROJECT_DATABASE))
    52  				}
    53  
    54  				{
    55  					req := &applet_mgr.GetProjectEnv{ProjectName: projectName}
    56  
    57  					rsp, _, err := client.GetProjectEnv(req)
    58  					NewWithT(t).Expect(err).To(BeNil())
    59  					NewWithT(t).Expect(rsp.ConfigType()).
    60  						To(Equal(enums.CONFIG_TYPE__PROJECT_ENV))
    61  				}
    62  
    63  				// remove project
    64  				{
    65  					req := &applet_mgr.RemoveProject{ProjectName: projectName}
    66  					_, err := client.RemoveProject(req)
    67  					NewWithT(t).Expect(err).To(BeNil())
    68  				}
    69  
    70  				// check project config is removed
    71  				{
    72  					_, err := config.GetByRelAndType(ctx, projectID, enums.CONFIG_TYPE__PROJECT_DATABASE)
    73  					requires.CheckError(t, err, status.ConfigNotFound)
    74  				}
    75  
    76  				{
    77  					_, err := config.GetByRelAndType(ctx, projectID, enums.CONFIG_TYPE__PROJECT_ENV)
    78  					requires.CheckError(t, err, status.ConfigNotFound)
    79  				}
    80  			})
    81  			t.Run("#InvalidProjectName", func(t *testing.T) {
    82  				// project name is empty
    83  				{
    84  					req := &applet_mgr.CreateProject{}
    85  
    86  					_, _, err := client.CreateProject(req)
    87  					requires.CheckError(t, err, &statusx.StatusErr{
    88  						Key: "badRequest",
    89  					})
    90  				}
    91  
    92  				{
    93  					req := &applet_mgr.CreateProject{}
    94  					req.CreateReq.Name = strings.Repeat("a", 33)
    95  
    96  					_, _, err := client.CreateProject(req)
    97  					requires.CheckError(t, err, &statusx.StatusErr{
    98  						Key: "badRequest",
    99  					})
   100  				}
   101  
   102  			})
   103  		})
   104  	})
   105  }