diff --git a/core/apps/utils.go b/core/apps/utils.go index 25e48c5e4..a524b4675 100644 --- a/core/apps/utils.go +++ b/core/apps/utils.go @@ -31,10 +31,3 @@ func initModule(name string, fn func() error) (err error) { log.Info(fmt.Sprintf("initialized %s successfully", name)) return nil } - -func initApp(name string, app App) { - _ = initModule(name, func() error { - app.Init() - return nil - }) -} diff --git a/core/cmd/root.go b/core/cmd/root.go index d9a11d2f2..108e016b1 100644 --- a/core/cmd/root.go +++ b/core/cmd/root.go @@ -23,11 +23,6 @@ func Execute() error { return rootCmd.Execute() } -// GetRootCmd get rootCmd instance -func GetRootCmd() *cobra.Command { - return rootCmd -} - func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "c", "", "Use Custom Config File") } diff --git a/core/config/version.go b/core/config/version.go deleted file mode 100644 index 4bcbf0661..000000000 --- a/core/config/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package config - -import "strings" - -const Version = "v0.6.3" - -func GetVersion() (v string) { - if strings.HasPrefix(Version, "v") { - return Version - } - return "v" + Version -} diff --git a/core/fs/service_v2_test.go b/core/fs/service_v2_test.go index 09191305d..f3006f5db 100644 --- a/core/fs/service_v2_test.go +++ b/core/fs/service_v2_test.go @@ -1,7 +1,7 @@ package fs import ( - "io/ioutil" + "github.com/apex/log" "os" "path/filepath" "testing" @@ -10,20 +10,25 @@ import ( ) func TestServiceV2_List(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() testDir := filepath.Join(rootDir, "dir") - os.Mkdir(testDir, 0755) - ioutil.WriteFile(filepath.Join(testDir, "file1.txt"), []byte("hello world"), 0644) - ioutil.WriteFile(filepath.Join(testDir, "file2.txt"), []byte("hello again"), 0644) + _ = os.Mkdir(testDir, 0755) + _ = os.WriteFile(filepath.Join(testDir, "file1.txt"), []byte("hello world"), 0644) + _ = os.WriteFile(filepath.Join(testDir, "file2.txt"), []byte("hello again"), 0644) subDir := filepath.Join(testDir, "subdir") - os.Mkdir(subDir, 0755) - ioutil.WriteFile(filepath.Join(subDir, "file3.txt"), []byte("subdir file"), 0644) - os.Mkdir(filepath.Join(testDir, "empty"), 0755) // explicitly testing empty dir inclusion + _ = os.Mkdir(subDir, 0755) + _ = os.WriteFile(filepath.Join(subDir, "file3.txt"), []byte("subdir file"), 0644) + _ = os.Mkdir(filepath.Join(testDir, "empty"), 0755) // explicitly testing empty dir inclusion svc := NewFsServiceV2(rootDir) @@ -56,14 +61,19 @@ func TestServiceV2_List(t *testing.T) { } func TestServiceV2_GetFile(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() expectedContent := []byte("hello world") - ioutil.WriteFile(filepath.Join(rootDir, "file.txt"), expectedContent, 0644) + _ = os.WriteFile(filepath.Join(rootDir, "file.txt"), expectedContent, 0644) svc := NewFsServiceV2(rootDir) @@ -75,14 +85,19 @@ func TestServiceV2_GetFile(t *testing.T) { } func TestServiceV2_Delete(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() filePath := filepath.Join(rootDir, "file.txt") - ioutil.WriteFile(filePath, []byte("hello world"), 0644) + _ = os.WriteFile(filePath, []byte("hello world"), 0644) svc := NewFsServiceV2(rootDir) @@ -98,11 +113,16 @@ func TestServiceV2_Delete(t *testing.T) { } func TestServiceV2_CreateDir(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() svc := NewFsServiceV2(rootDir) @@ -118,11 +138,16 @@ func TestServiceV2_CreateDir(t *testing.T) { } func TestServiceV2_Save(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() svc := NewFsServiceV2(rootDir) @@ -133,22 +158,27 @@ func TestServiceV2_Save(t *testing.T) { } // Verify the file was saved - data, err := ioutil.ReadFile(filepath.Join(rootDir, "newFile.txt")) + data, err := os.ReadFile(filepath.Join(rootDir, "newFile.txt")) assert.NoError(t, err) assert.Equal(t, "Hello, world!", string(data)) } func TestServiceV2_Rename(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() svc := NewFsServiceV2(rootDir) // Create a file to rename - ioutil.WriteFile(filepath.Join(rootDir, "oldName.txt"), []byte("Hello, world!"), 0644) + _ = os.WriteFile(filepath.Join(rootDir, "oldName.txt"), []byte("Hello, world!"), 0644) // Rename the file err = svc.Rename("oldName.txt", "newName.txt") @@ -162,16 +192,21 @@ func TestServiceV2_Rename(t *testing.T) { } func TestServiceV2_RenameDir(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() svc := NewFsServiceV2(rootDir) // Create a directory to rename - os.Mkdir(filepath.Join(rootDir, "oldName"), 0755) + _ = os.Mkdir(filepath.Join(rootDir, "oldName"), 0755) // Rename the directory err = svc.Rename("oldName", "newName") @@ -185,16 +220,21 @@ func TestServiceV2_RenameDir(t *testing.T) { } func TestServiceV2_Copy(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() svc := NewFsServiceV2(rootDir) // Create a file to copy - ioutil.WriteFile(filepath.Join(rootDir, "source.txt"), []byte("Hello, world!"), 0644) + _ = os.WriteFile(filepath.Join(rootDir, "source.txt"), []byte("Hello, world!"), 0644) // Copy the file err = svc.Copy("source.txt", "copy.txt") @@ -203,23 +243,28 @@ func TestServiceV2_Copy(t *testing.T) { } // Verify the file was copied - data, err := ioutil.ReadFile(filepath.Join(rootDir, "copy.txt")) + data, err := os.ReadFile(filepath.Join(rootDir, "copy.txt")) assert.NoError(t, err) assert.Equal(t, "Hello, world!", string(data)) } func TestServiceV2_CopyDir(t *testing.T) { - rootDir, err := ioutil.TempDir("", "fsTest") + rootDir, err := os.MkdirTemp("", "fsTest") if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } - defer os.RemoveAll(rootDir) // clean up + defer func() { + err := os.RemoveAll(rootDir) // clean up + if err != nil { + log.Errorf("Failed to remove temp dir: %v", err) + } + }() svc := NewFsServiceV2(rootDir) // Create a directory to copy - os.Mkdir(filepath.Join(rootDir, "sourceDir"), 0755) - ioutil.WriteFile(filepath.Join(rootDir, "sourceDir", "file.txt"), []byte("Hello, world!"), 0644) + _ = os.Mkdir(filepath.Join(rootDir, "sourceDir"), 0755) + _ = os.WriteFile(filepath.Join(rootDir, "sourceDir", "file.txt"), []byte("Hello, world!"), 0644) // Copy the directory err = svc.Copy("sourceDir", "copyDir") @@ -232,7 +277,7 @@ func TestServiceV2_CopyDir(t *testing.T) { assert.NoError(t, err) // Verify the file inside the directory was copied - data, err := ioutil.ReadFile(filepath.Join(rootDir, "copyDir", "file.txt")) + data, err := os.ReadFile(filepath.Join(rootDir, "copyDir", "file.txt")) assert.NoError(t, err) assert.Equal(t, "Hello, world!", string(data)) } diff --git a/core/grpc/server/model_base_service_v2_server.go b/core/grpc/server/model_base_service_v2_server.go index eefd389a6..7f356ec4f 100644 --- a/core/grpc/server/model_base_service_v2_server.go +++ b/core/grpc/server/model_base_service_v2_server.go @@ -63,7 +63,7 @@ type ModelBaseServiceServerV2 struct { grpc.UnimplementedModelBaseServiceV2Server } -func (svr ModelBaseServiceServerV2) GetById(ctx context.Context, req *grpc.ModelServiceV2GetByIdRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) GetById(_ context.Context, req *grpc.ModelServiceV2GetByIdRequest) (res *grpc.Response, err error) { id, err := primitive.ObjectIDFromHex(req.Id) if err != nil { return HandleError(err) @@ -76,7 +76,7 @@ func (svr ModelBaseServiceServerV2) GetById(ctx context.Context, req *grpc.Model return HandleSuccessWithData(data) } -func (svr ModelBaseServiceServerV2) GetOne(ctx context.Context, req *grpc.ModelServiceV2GetOneRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) GetOne(_ context.Context, req *grpc.ModelServiceV2GetOneRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { @@ -95,7 +95,7 @@ func (svr ModelBaseServiceServerV2) GetOne(ctx context.Context, req *grpc.ModelS return HandleSuccessWithData(data) } -func (svr ModelBaseServiceServerV2) GetMany(ctx context.Context, req *grpc.ModelServiceV2GetManyRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) GetMany(_ context.Context, req *grpc.ModelServiceV2GetManyRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { @@ -114,7 +114,7 @@ func (svr ModelBaseServiceServerV2) GetMany(ctx context.Context, req *grpc.Model return HandleSuccessWithData(data) } -func (svr ModelBaseServiceServerV2) DeleteById(ctx context.Context, req *grpc.ModelServiceV2DeleteByIdRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) DeleteById(_ context.Context, req *grpc.ModelServiceV2DeleteByIdRequest) (res *grpc.Response, err error) { id, err := primitive.ObjectIDFromHex(req.Id) if err != nil { return HandleError(err) @@ -127,7 +127,7 @@ func (svr ModelBaseServiceServerV2) DeleteById(ctx context.Context, req *grpc.Mo return HandleSuccess() } -func (svr ModelBaseServiceServerV2) DeleteOne(ctx context.Context, req *grpc.ModelServiceV2DeleteOneRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) DeleteOne(_ context.Context, req *grpc.ModelServiceV2DeleteOneRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { @@ -141,7 +141,7 @@ func (svr ModelBaseServiceServerV2) DeleteOne(ctx context.Context, req *grpc.Mod return HandleSuccess() } -func (svr ModelBaseServiceServerV2) DeleteMany(ctx context.Context, req *grpc.ModelServiceV2DeleteManyRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) DeleteMany(_ context.Context, req *grpc.ModelServiceV2DeleteManyRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { @@ -155,7 +155,7 @@ func (svr ModelBaseServiceServerV2) DeleteMany(ctx context.Context, req *grpc.Mo return HandleSuccess() } -func (svr ModelBaseServiceServerV2) UpdateById(ctx context.Context, req *grpc.ModelServiceV2UpdateByIdRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) UpdateById(_ context.Context, req *grpc.ModelServiceV2UpdateByIdRequest) (res *grpc.Response, err error) { id, err := primitive.ObjectIDFromHex(req.Id) if err != nil { return HandleError(err) @@ -173,7 +173,7 @@ func (svr ModelBaseServiceServerV2) UpdateById(ctx context.Context, req *grpc.Mo return HandleSuccess() } -func (svr ModelBaseServiceServerV2) UpdateOne(ctx context.Context, req *grpc.ModelServiceV2UpdateOneRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) UpdateOne(_ context.Context, req *grpc.ModelServiceV2UpdateOneRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { @@ -192,7 +192,7 @@ func (svr ModelBaseServiceServerV2) UpdateOne(ctx context.Context, req *grpc.Mod return HandleSuccess() } -func (svr ModelBaseServiceServerV2) UpdateMany(ctx context.Context, req *grpc.ModelServiceV2UpdateManyRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) UpdateMany(_ context.Context, req *grpc.ModelServiceV2UpdateManyRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { @@ -211,7 +211,7 @@ func (svr ModelBaseServiceServerV2) UpdateMany(ctx context.Context, req *grpc.Mo return HandleSuccess() } -func (svr ModelBaseServiceServerV2) ReplaceById(ctx context.Context, req *grpc.ModelServiceV2ReplaceByIdRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) ReplaceById(_ context.Context, req *grpc.ModelServiceV2ReplaceByIdRequest) (res *grpc.Response, err error) { id, err := primitive.ObjectIDFromHex(req.Id) if err != nil { return HandleError(err) @@ -231,7 +231,7 @@ func (svr ModelBaseServiceServerV2) ReplaceById(ctx context.Context, req *grpc.M return HandleSuccess() } -func (svr ModelBaseServiceServerV2) ReplaceOne(ctx context.Context, req *grpc.ModelServiceV2ReplaceOneRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) ReplaceOne(_ context.Context, req *grpc.ModelServiceV2ReplaceOneRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { @@ -252,7 +252,7 @@ func (svr ModelBaseServiceServerV2) ReplaceOne(ctx context.Context, req *grpc.Mo return HandleSuccess() } -func (svr ModelBaseServiceServerV2) InsertOne(ctx context.Context, req *grpc.ModelServiceV2InsertOneRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) InsertOne(_ context.Context, req *grpc.ModelServiceV2InsertOneRequest) (res *grpc.Response, err error) { model := GetOneInstanceModel(req.ModelType) modelType := reflect.TypeOf(model) modelValuePtr := reflect.New(modelType).Interface() @@ -268,7 +268,7 @@ func (svr ModelBaseServiceServerV2) InsertOne(ctx context.Context, req *grpc.Mod return HandleSuccessWithData(r.InsertedID) } -func (svr ModelBaseServiceServerV2) InsertMany(ctx context.Context, req *grpc.ModelServiceV2InsertManyRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) InsertMany(_ context.Context, req *grpc.ModelServiceV2InsertManyRequest) (res *grpc.Response, err error) { model := GetOneInstanceModel(req.ModelType) modelType := reflect.TypeOf(model) modelsSliceType := reflect.SliceOf(modelType) @@ -290,7 +290,7 @@ func (svr ModelBaseServiceServerV2) InsertMany(ctx context.Context, req *grpc.Mo return HandleSuccessWithData(r.InsertedIDs) } -func (svr ModelBaseServiceServerV2) Count(ctx context.Context, req *grpc.ModelServiceV2CountRequest) (res *grpc.Response, err error) { +func (svr ModelBaseServiceServerV2) Count(_ context.Context, req *grpc.ModelServiceV2CountRequest) (res *grpc.Response, err error) { var query bson.M err = json.Unmarshal(req.Query, &query) if err != nil { diff --git a/core/models/client/model_service_v2_test.go b/core/models/client/model_service_v2_test.go index 7bd5ac5fd..6738af4ae 100644 --- a/core/models/client/model_service_v2_test.go +++ b/core/models/client/model_service_v2_test.go @@ -2,6 +2,7 @@ package client_test import ( "context" + "github.com/apex/log" "github.com/crawlab-team/crawlab/core/grpc/server" "github.com/crawlab-team/crawlab/core/models/client" "github.com/crawlab-team/crawlab/core/models/models/v2" @@ -28,13 +29,27 @@ func teardownTestDB() { db.Drop(context.Background()) } +func startSvr(svr *server.GrpcServerV2) { + err := svr.Start() + if err != nil { + log.Errorf("failed to start grpc server: %v", err) + } +} + +func stopSvr(svr *server.GrpcServerV2) { + err := svr.Stop() + if err != nil { + log.Errorf("failed to stop grpc server: %v", err) + } +} + func TestModelServiceV2_GetById(t *testing.T) { setupTestDB() defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -45,7 +60,7 @@ func TestModelServiceV2_GetById(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -61,8 +76,8 @@ func TestModelServiceV2_GetOne(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -73,7 +88,7 @@ func TestModelServiceV2_GetOne(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -89,8 +104,8 @@ func TestModelServiceV2_GetMany(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -101,7 +116,7 @@ func TestModelServiceV2_GetMany(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -118,8 +133,8 @@ func TestModelServiceV2_DeleteById(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -130,7 +145,7 @@ func TestModelServiceV2_DeleteById(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -148,8 +163,8 @@ func TestModelServiceV2_DeleteOne(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -160,7 +175,7 @@ func TestModelServiceV2_DeleteOne(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -178,8 +193,8 @@ func TestModelServiceV2_DeleteMany(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -190,7 +205,7 @@ func TestModelServiceV2_DeleteMany(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -208,8 +223,8 @@ func TestModelServiceV2_UpdateById(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -220,7 +235,7 @@ func TestModelServiceV2_UpdateById(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -238,8 +253,8 @@ func TestModelServiceV2_UpdateOne(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -250,7 +265,7 @@ func TestModelServiceV2_UpdateOne(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -268,8 +283,8 @@ func TestModelServiceV2_UpdateMany(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m1 := TestModel{ Name: "Test Name", @@ -284,7 +299,7 @@ func TestModelServiceV2_UpdateMany(t *testing.T) { require.Nil(t, err) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -302,8 +317,8 @@ func TestModelServiceV2_ReplaceById(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -314,7 +329,7 @@ func TestModelServiceV2_ReplaceById(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -333,8 +348,8 @@ func TestModelServiceV2_ReplaceOne(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) m := TestModel{ Name: "Test Name", @@ -345,7 +360,7 @@ func TestModelServiceV2_ReplaceOne(t *testing.T) { m.SetId(id) time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -364,10 +379,10 @@ func TestModelServiceV2_InsertOne(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() @@ -388,25 +403,25 @@ func TestModelServiceV2_InsertMany(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() clientSvc := client.NewModelServiceV2[TestModel]() - models := []TestModel{ + testModels := []TestModel{ {Name: "Test Name 1"}, {Name: "Test Name 2"}, } - ids, err := clientSvc.InsertMany(models) + ids, err := clientSvc.InsertMany(testModels) require.Nil(t, err) for i, id := range ids { res, err := clientSvc.GetById(id) require.Nil(t, err) - assert.Equal(t, res.Name, models[i].Name) + assert.Equal(t, res.Name, testModels[i].Name) } } @@ -415,8 +430,8 @@ func TestModelServiceV2_Count(t *testing.T) { defer teardownTestDB() svr, err := server.NewGrpcServerV2() require.Nil(t, err) - go svr.Start() - defer svr.Stop() + go startSvr(svr) + defer stopSvr(svr) modelSvc := service.NewModelServiceV2[TestModel]() for i := 0; i < 5; i++ { @@ -427,7 +442,7 @@ func TestModelServiceV2_Count(t *testing.T) { } time.Sleep(100 * time.Millisecond) - c, err := grpc.Dial("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) + c, err := grpc.NewClient("localhost:9666", grpc.WithTransportCredentials(insecure.NewCredentials())) require.Nil(t, err) c.Connect() diff --git a/frontend/index.html b/frontend/index.html index c42f06c83..ccaeab84e 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -12,7 +12,6 @@ -