From dd98bf121b0130e9e5bb9fb24fa7848dc1762d58 Mon Sep 17 00:00:00 2001 From: Pavel Avilov Date: Fri, 25 Feb 2022 12:04:19 +0300 Subject: [PATCH 1/4] Increase test coverage for the environment package --- .../internal/environment/application_test.go | 56 +++++- .../backend/internal/environment/beam_test.go | 41 +++- .../environment/environment_service_test.go | 180 ++++++++++++++++-- 3 files changed, 247 insertions(+), 30 deletions(-) diff --git a/playground/backend/internal/environment/application_test.go b/playground/backend/internal/environment/application_test.go index 92f2aeb1ec8db..91a02ed58034d 100644 --- a/playground/backend/internal/environment/application_test.go +++ b/playground/backend/internal/environment/application_test.go @@ -33,7 +33,7 @@ func TestNetworkEnvs_Address(t *testing.T) { want string }{ { - name: "ip and port concatenated through ':'", + name: "Ip and port concatenated through ':'", fields: fields{ip: defaultIp, port: defaultPort}, want: fmt.Sprintf("%s:%d", defaultIp, defaultPort), }, @@ -63,7 +63,7 @@ func TestCacheEnvs_CacheType(t *testing.T) { want string }{ { - name: "all success", + name: "All success", fields: fields{ cacheType: "MOCK_CACHE_TYPE", address: "MOCK_ADDRESS", @@ -98,7 +98,7 @@ func TestCacheEnvs_Address(t *testing.T) { want string }{ { - name: "all success", + name: "All success", fields: fields{ cacheType: "MOCK_CACHE_TYPE", address: "MOCK_ADDRESS", @@ -133,7 +133,7 @@ func TestCacheEnvs_KeyExpirationTime(t *testing.T) { want time.Duration }{ { - name: "all success", + name: "All success", fields: fields{ cacheType: "MOCK_CACHE_TYPE", address: "MOCK_ADDRESS", @@ -168,7 +168,7 @@ func TestApplicationEnvs_WorkingDir(t *testing.T) { want string }{ { - name: "all success", + name: "All success", fields: fields{ workingDir: "MOCK_WORKING_DIR", cacheEnvs: &CacheEnvs{}, @@ -203,7 +203,7 @@ func TestApplicationEnvs_CacheEnvs(t *testing.T) { want *CacheEnvs }{ { - name: "all success", + name: "All success", fields: fields{ workingDir: "MOCK_WORKING_DIR", cacheEnvs: &CacheEnvs{}, @@ -238,7 +238,7 @@ func TestApplicationEnvs_PipelineExecuteTimeout(t *testing.T) { want time.Duration }{ { - name: "all success", + name: "All success", fields: fields{ workingDir: "MOCK_WORKING_DIR", cacheEnvs: &CacheEnvs{}, @@ -277,7 +277,7 @@ func TestApplicationEnvs_LaunchSite(t *testing.T) { { // Test case with calling LaunchSite method. // As a result, want to receive an expected launch site. - name: "get launch site", + name: "Get launch site", fields: fields{ workingDir: "", cacheEnvs: &CacheEnvs{}, @@ -318,7 +318,7 @@ func TestApplicationEnvs_GoogleProjectId(t *testing.T) { { // Test case with calling GoogleProjectId method. // As a result, want to receive an expected project id. - name: "get google project id", + name: "Get google project id", fields: fields{ workingDir: "", cacheEnvs: &CacheEnvs{}, @@ -358,7 +358,7 @@ func TestApplicationEnvs_PipelinesFolder(t *testing.T) { { // Test case with calling PipelinesFolder method. // As a result, want to receive an expected name of pipelines folder. - name: "get google project id", + name: "Get google project id", fields: fields{ workingDir: "", cacheEnvs: &CacheEnvs{}, @@ -382,3 +382,39 @@ func TestApplicationEnvs_PipelinesFolder(t *testing.T) { }) } } + +func TestNetworkEnvs_Protocol(t *testing.T) { + protocol := "HTTP" + type fields struct { + ip string + port int + protocol string + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "All success", + fields: fields{ + ip: "", + port: 0, + protocol: protocol, + }, + want: protocol, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + serverEnvs := &NetworkEnvs{ + ip: tt.fields.ip, + port: tt.fields.port, + protocol: tt.fields.protocol, + } + if got := serverEnvs.Protocol(); got != tt.want { + t.Errorf("Protocol() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/playground/backend/internal/environment/beam_test.go b/playground/backend/internal/environment/beam_test.go index 53b515b6c4cc3..6d0a24cb5633b 100644 --- a/playground/backend/internal/environment/beam_test.go +++ b/playground/backend/internal/environment/beam_test.go @@ -33,7 +33,7 @@ func TestBeamEnvs_PreparedModDir(t *testing.T) { want string }{ { - name: "get path to prepared directory of the go.mod", + name: "Get path to prepared directory of the go.mod", fields: fields{ ApacheBeamSdk: 0, ExecutorConfig: nil, @@ -55,3 +55,42 @@ func TestBeamEnvs_PreparedModDir(t *testing.T) { }) } } + +func TestBeamEnvs_NumOfParallelJobs(t *testing.T) { + numOfParallelJobs := 2 + type fields struct { + ApacheBeamSdk playground.Sdk + ExecutorConfig *ExecutorConfig + preparedModDir string + numOfParallelJobs int + } + tests := []struct { + name string + fields fields + want int + }{ + { + name: "All success", + fields: fields{ + ApacheBeamSdk: 0, + ExecutorConfig: nil, + preparedModDir: "", + numOfParallelJobs: numOfParallelJobs, + }, + want: numOfParallelJobs, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + b := &BeamEnvs{ + ApacheBeamSdk: tt.fields.ApacheBeamSdk, + ExecutorConfig: tt.fields.ExecutorConfig, + preparedModDir: tt.fields.preparedModDir, + numOfParallelJobs: tt.fields.numOfParallelJobs, + } + if got := b.NumOfParallelJobs(); got != tt.want { + t.Errorf("NumOfParallelJobs() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/playground/backend/internal/environment/environment_service_test.go b/playground/backend/internal/environment/environment_service_test.go index 94bc2eda194a3..dffcaa0bdd059 100644 --- a/playground/backend/internal/environment/environment_service_test.go +++ b/playground/backend/internal/environment/environment_service_test.go @@ -16,17 +16,21 @@ package environment import ( - playground "beam.apache.org/playground/backend/internal/api/v1" + pb "beam.apache.org/playground/backend/internal/api/v1" "fmt" "io/fs" "os" "path/filepath" "reflect" "testing" + "time" ) const ( javaConfig = "{\n \"compile_cmd\": \"javac\",\n \"run_cmd\": \"java\",\n \"test_cmd\": \"java\",\n \"compile_args\": [\n \"-d\",\n \"bin\",\n \"-classpath\"\n ],\n \"run_args\": [\n \"-cp\",\n \"bin:\"\n ],\n \"test_args\": [\n \"-cp\",\n \"bin:\",\n \"org.junit.runner.JUnitCore\"\n ]\n}" + goConfig = "{\n \"compile_cmd\": \"go\",\n \"run_cmd\": \"\",\n \"test_cmd\": \"go\",\n \"compile_args\": [\n \"build\",\n \"-o\",\n \"bin\"\n ],\n \"run_args\": [\n ],\n \"test_args\": [\n \"test\",\n \"-v\"\n ]\n}\n" + pythonConfig = "{\n \"compile_cmd\": \"\",\n \"run_cmd\": \"python3\",\n \"test_cmd\": \"pytest\",\n \"compile_args\": [],\n \"run_args\": [],\n \"test_args\": []\n}\n" + scioConfig = "{\n \"compile_cmd\": \"\",\n \"run_cmd\": \"sbt\",\n \"test_cmd\": \"sbt\",\n \"compile_args\": [],\n \"run_args\": [\n \"runMain\"\n ],\n \"test_args\": []\n}\n" defaultProjectId = "" ) @@ -46,8 +50,14 @@ func setup() error { if err != nil { return err } - filePath := filepath.Join(configFolderName, defaultSdk.String()+jsonExt) - err = os.WriteFile(filePath, []byte(javaConfig), 0600) + javaConfigPath := filepath.Join(configFolderName, defaultSdk.String()+jsonExt) + err = os.WriteFile(javaConfigPath, []byte(javaConfig), 0600) + goConfigPath := filepath.Join(configFolderName, pb.Sdk_SDK_GO.String()+jsonExt) + err = os.WriteFile(goConfigPath, []byte(goConfig), 0600) + pythonConfigPath := filepath.Join(configFolderName, pb.Sdk_SDK_PYTHON.String()+jsonExt) + err = os.WriteFile(pythonConfigPath, []byte(pythonConfig), 0600) + scioConfigPath := filepath.Join(configFolderName, pb.Sdk_SDK_SCIO.String()+jsonExt) + err = os.WriteFile(scioConfigPath, []byte(scioConfig), 0600) if err != nil { return err } @@ -90,7 +100,7 @@ func TestNewEnvironment(t *testing.T) { name string want *Environment }{ - {name: "create env service with default envs", want: &Environment{ + {name: "Create env service with default envs", want: &Environment{ NetworkEnvs: *NewNetworkEnvs(defaultIp, defaultPort, defaultProtocol), BeamSdkEnvs: *NewBeamEnvs(defaultSdk, executorConfig, preparedModDir, 0), ApplicationEnvs: *NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout), @@ -118,26 +128,26 @@ func Test_getSdkEnvsFromOsEnvs(t *testing.T) { wantErr bool }{ { - name: "not specified beam sdk key in os envs", - want: NewBeamEnvs(playground.Sdk_SDK_UNSPECIFIED, nil, preparedModDir, defaultNumOfParallelJobs), + name: "Not specified beam sdk key in os envs", + want: NewBeamEnvs(pb.Sdk_SDK_UNSPECIFIED, nil, preparedModDir, defaultNumOfParallelJobs), envsToSet: map[string]string{}, wantErr: false, }, { - name: "default beam envs", + name: "Default beam envs", want: NewBeamEnvs(defaultSdk, executorConfig, preparedModDir, defaultNumOfParallelJobs), envsToSet: map[string]string{beamSdkKey: "SDK_JAVA"}, wantErr: false, }, { - name: "specific sdk key in os envs", + name: "Specific sdk key in os envs", want: NewBeamEnvs(defaultSdk, executorConfig, preparedModDir, defaultNumOfParallelJobs), envsToSet: map[string]string{beamSdkKey: "SDK_JAVA"}, wantErr: false, }, { - name: "wrong sdk key in os envs", - want: NewBeamEnvs(playground.Sdk_SDK_UNSPECIFIED, nil, preparedModDir, defaultNumOfParallelJobs), + name: "Wrong sdk key in os envs", + want: NewBeamEnvs(pb.Sdk_SDK_UNSPECIFIED, nil, preparedModDir, defaultNumOfParallelJobs), envsToSet: map[string]string{beamSdkKey: "SDK_J"}, wantErr: false, }, @@ -168,16 +178,16 @@ func Test_getNetworkEnvsFromOsEnvs(t *testing.T) { wantErr bool }{ { - name: "default values", + name: "Default values", want: NewNetworkEnvs(defaultIp, defaultPort, defaultProtocol), }, { - name: "values from os envs", + name: "Values from os envs", want: NewNetworkEnvs("12.12.12.21", 1234, "TCP"), envsToSet: map[string]string{serverIpKey: "12.12.12.21", serverPortKey: "1234", protocolTypeKey: "TCP"}, }, { - name: "not int port in os env, should be default", + name: "Not int port in os env, should be default", want: nil, envsToSet: map[string]string{serverIpKey: "12.12.12.21", serverPortKey: "1a34"}, wantErr: true, @@ -202,6 +212,8 @@ func Test_getNetworkEnvsFromOsEnvs(t *testing.T) { } func Test_getApplicationEnvsFromOsEnvs(t *testing.T) { + hour := "1h" + convertedTime, _ := time.ParseDuration(hour) tests := []struct { name string want *ApplicationEnvs @@ -209,16 +221,40 @@ func Test_getApplicationEnvsFromOsEnvs(t *testing.T) { envsToSet map[string]string }{ { - name: "working dir is provided", + name: "Working dir is provided", want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout), wantErr: false, envsToSet: map[string]string{workingDirKey: "/app", launchSiteKey: defaultLaunchSite, projectIdKey: defaultProjectId}, }, { - name: "working dir isn't provided", + name: "Working dir isn't provided", want: nil, wantErr: true, }, + { + name: "CacheKeyExpirationTimeKey is set with the correct value", + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, convertedTime}, defaultPipelineExecuteTimeout), + wantErr: false, + envsToSet: map[string]string{workingDirKey: "/app", cacheKeyExpirationTimeKey: hour}, + }, + { + name: "CacheKeyExpirationTimeKey is set with the incorrect value", + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout), + wantErr: false, + envsToSet: map[string]string{workingDirKey: "/app", cacheKeyExpirationTimeKey: "1"}, + }, + { + name: "CacheKeyExpirationTimeKey is set with the correct value", + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, convertedTime), + wantErr: false, + envsToSet: map[string]string{workingDirKey: "/app", pipelineExecuteTimeoutKey: hour}, + }, + { + name: "PipelineExecuteTimeoutKey is set with the incorrect value", + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout), + wantErr: false, + envsToSet: map[string]string{workingDirKey: "/app", pipelineExecuteTimeoutKey: "1"}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -242,7 +278,7 @@ func Test_getApplicationEnvsFromOsEnvs(t *testing.T) { func Test_createExecutorConfig(t *testing.T) { type args struct { - apacheBeamSdk playground.Sdk + apacheBeamSdk pb.Sdk configPath string } tests := []struct { @@ -252,7 +288,7 @@ func Test_createExecutorConfig(t *testing.T) { wantErr bool }{ { - name: "create executor configuration from json file", + name: "Create executor configuration from json file", args: args{apacheBeamSdk: defaultSdk, configPath: filepath.Join(configFolderName, defaultSdk.String()+jsonExt)}, want: executorConfig, wantErr: false, @@ -283,13 +319,13 @@ func Test_getConfigFromJson(t *testing.T) { wantErr bool }{ { - name: "get object from json", + name: "Get object from json", args: args{filepath.Join(configFolderName, defaultSdk.String()+jsonExt)}, want: NewExecutorConfig("javac", "java", "java", []string{"-d", "bin", "-classpath"}, []string{"-cp", "bin:"}, []string{"-cp", "bin:", "org.junit.runner.JUnitCore"}), wantErr: false, }, { - name: "error if wrong json path", + name: "Error if wrong json path", args: args{filepath.Join("wrong_folder", defaultSdk.String()+jsonExt)}, want: nil, wantErr: true, @@ -308,3 +344,109 @@ func Test_getConfigFromJson(t *testing.T) { }) } } + +func TestConfigureBeamEnvs(t *testing.T) { + workingDir := "./" + modDir := "/modDir" + goExecutorConfig := NewExecutorConfig( + "go", + "", + "go", + []string{"build", "-o", "bin"}, + []string{}, + []string{"test", "-v"}, + ) + pythonExecutorConfig := NewExecutorConfig( + "", + "python3", + "pytest", + []string{}, + []string{}, + []string{}, + ) + scioExecutorConfig := NewExecutorConfig( + "", + "sbt", + "sbt", + []string{}, + []string{"runMain"}, + []string{}, + ) + type args struct { + workingDir string + } + tests := []struct { + name string + args args + want *BeamEnvs + wantErr bool + envsToSet map[string]string + }{ + { + name: "PREPARED_MOD_DIR not be specified in the environment for GO sdk", + args: args{workingDir: workingDir}, + want: nil, + wantErr: true, + envsToSet: map[string]string{beamSdkKey: "SDK_GO"}, + }, + { + name: "BeamSdkKey set to GO sdk", + args: args{workingDir: workingDir}, + want: NewBeamEnvs(pb.Sdk_SDK_GO, goExecutorConfig, modDir, defaultNumOfParallelJobs), + wantErr: false, + envsToSet: map[string]string{beamSdkKey: "SDK_GO", preparedModDirKey: modDir}, + }, + { + name: "Error during creating executable config", + args: args{workingDir: "/app"}, + want: nil, + wantErr: true, + envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON"}, + }, + { + name: "BeamSdkKey set to Python sdk", + want: NewBeamEnvs(pb.Sdk_SDK_PYTHON, pythonExecutorConfig, modDir, defaultNumOfParallelJobs), + wantErr: false, + envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON"}, + }, + { + name: "BeamSdkKey set to SCIO sdk", + want: NewBeamEnvs(pb.Sdk_SDK_SCIO, scioExecutorConfig, modDir, defaultNumOfParallelJobs), + wantErr: false, + envsToSet: map[string]string{beamSdkKey: "SDK_SCIO"}, + }, + { + name: "NumOfParallelJobsKey is set with with a positive number", + want: NewBeamEnvs(pb.Sdk_SDK_PYTHON, pythonExecutorConfig, modDir, 1), + wantErr: false, + envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON", numOfParallelJobsKey: "1"}, + }, + { + name: "NumOfParallelJobsKey is set with with a negative number", + want: NewBeamEnvs(pb.Sdk_SDK_PYTHON, pythonExecutorConfig, modDir, defaultNumOfParallelJobs), + wantErr: false, + envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON", numOfParallelJobsKey: "-1"}, + }, + { + name: "NumOfParallelJobsKey is set with with incorrect value", + want: NewBeamEnvs(pb.Sdk_SDK_PYTHON, pythonExecutorConfig, modDir, defaultNumOfParallelJobs), + wantErr: false, + envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON", numOfParallelJobsKey: "incorrectValue"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := setOsEnvs(tt.envsToSet); err != nil { + t.Fatalf("couldn't setup os env") + } + got, err := ConfigureBeamEnvs(tt.args.workingDir) + if (err != nil) != tt.wantErr { + t.Errorf("ConfigureBeamEnvs() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ConfigureBeamEnvs() got = %v, want %v", got, tt.want) + } + }) + } +} From ab3762b61e7ecf5868f5e22be11d3255c222303b Mon Sep 17 00:00:00 2001 From: Pavel Avilov Date: Mon, 28 Feb 2022 09:25:45 +0300 Subject: [PATCH 2/4] Update test names --- .../internal/environment/application_test.go | 16 ++++++++-------- .../backend/internal/environment/beam_test.go | 2 +- .../environment/environment_service_test.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/playground/backend/internal/environment/application_test.go b/playground/backend/internal/environment/application_test.go index 91a02ed58034d..f81e4a7ae40e5 100644 --- a/playground/backend/internal/environment/application_test.go +++ b/playground/backend/internal/environment/application_test.go @@ -63,7 +63,7 @@ func TestCacheEnvs_CacheType(t *testing.T) { want string }{ { - name: "All success", + name: "Get cache type", fields: fields{ cacheType: "MOCK_CACHE_TYPE", address: "MOCK_ADDRESS", @@ -98,7 +98,7 @@ func TestCacheEnvs_Address(t *testing.T) { want string }{ { - name: "All success", + name: "Get cache address", fields: fields{ cacheType: "MOCK_CACHE_TYPE", address: "MOCK_ADDRESS", @@ -133,7 +133,7 @@ func TestCacheEnvs_KeyExpirationTime(t *testing.T) { want time.Duration }{ { - name: "All success", + name: "Get expiration time for cache keys", fields: fields{ cacheType: "MOCK_CACHE_TYPE", address: "MOCK_ADDRESS", @@ -168,7 +168,7 @@ func TestApplicationEnvs_WorkingDir(t *testing.T) { want string }{ { - name: "All success", + name: "Get working directory", fields: fields{ workingDir: "MOCK_WORKING_DIR", cacheEnvs: &CacheEnvs{}, @@ -203,7 +203,7 @@ func TestApplicationEnvs_CacheEnvs(t *testing.T) { want *CacheEnvs }{ { - name: "All success", + name: "Get cache environment variables", fields: fields{ workingDir: "MOCK_WORKING_DIR", cacheEnvs: &CacheEnvs{}, @@ -238,7 +238,7 @@ func TestApplicationEnvs_PipelineExecuteTimeout(t *testing.T) { want time.Duration }{ { - name: "All success", + name: "Get pipeline execute timeout", fields: fields{ workingDir: "MOCK_WORKING_DIR", cacheEnvs: &CacheEnvs{}, @@ -358,7 +358,7 @@ func TestApplicationEnvs_PipelinesFolder(t *testing.T) { { // Test case with calling PipelinesFolder method. // As a result, want to receive an expected name of pipelines folder. - name: "Get google project id", + name: "Get name of pipeline folder", fields: fields{ workingDir: "", cacheEnvs: &CacheEnvs{}, @@ -396,7 +396,7 @@ func TestNetworkEnvs_Protocol(t *testing.T) { want string }{ { - name: "All success", + name: "Get server protocol", fields: fields{ ip: "", port: 0, diff --git a/playground/backend/internal/environment/beam_test.go b/playground/backend/internal/environment/beam_test.go index 6d0a24cb5633b..cf6f58bfce0d9 100644 --- a/playground/backend/internal/environment/beam_test.go +++ b/playground/backend/internal/environment/beam_test.go @@ -70,7 +70,7 @@ func TestBeamEnvs_NumOfParallelJobs(t *testing.T) { want int }{ { - name: "All success", + name: "Get the number of parallel jobs", fields: fields{ ApacheBeamSdk: 0, ExecutorConfig: nil, diff --git a/playground/backend/internal/environment/environment_service_test.go b/playground/backend/internal/environment/environment_service_test.go index dffcaa0bdd059..839eda5c12bc9 100644 --- a/playground/backend/internal/environment/environment_service_test.go +++ b/playground/backend/internal/environment/environment_service_test.go @@ -383,7 +383,7 @@ func TestConfigureBeamEnvs(t *testing.T) { envsToSet map[string]string }{ { - name: "PREPARED_MOD_DIR not be specified in the environment for GO sdk", + name: "PREPARED_MOD_DIR is not specified in the environment for GO sdk", args: args{workingDir: workingDir}, want: nil, wantErr: true, From 5f85353a6013857e10707f0d0c0e989a6104d982 Mon Sep 17 00:00:00 2001 From: Pavel Avilov Date: Mon, 28 Feb 2022 15:23:44 +0300 Subject: [PATCH 3/4] Refactoring code --- .../environment/environment_service_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/playground/backend/internal/environment/environment_service_test.go b/playground/backend/internal/environment/environment_service_test.go index 839eda5c12bc9..bb676b0893694 100644 --- a/playground/backend/internal/environment/environment_service_test.go +++ b/playground/backend/internal/environment/environment_service_test.go @@ -32,6 +32,7 @@ const ( pythonConfig = "{\n \"compile_cmd\": \"\",\n \"run_cmd\": \"python3\",\n \"test_cmd\": \"pytest\",\n \"compile_args\": [],\n \"run_args\": [],\n \"test_args\": []\n}\n" scioConfig = "{\n \"compile_cmd\": \"\",\n \"run_cmd\": \"sbt\",\n \"test_cmd\": \"sbt\",\n \"compile_args\": [],\n \"run_args\": [\n \"runMain\"\n ],\n \"test_args\": []\n}\n" defaultProjectId = "" + dirPermission = 0600 ) var executorConfig *ExecutorConfig @@ -51,13 +52,13 @@ func setup() error { return err } javaConfigPath := filepath.Join(configFolderName, defaultSdk.String()+jsonExt) - err = os.WriteFile(javaConfigPath, []byte(javaConfig), 0600) + err = os.WriteFile(javaConfigPath, []byte(javaConfig), dirPermission) goConfigPath := filepath.Join(configFolderName, pb.Sdk_SDK_GO.String()+jsonExt) - err = os.WriteFile(goConfigPath, []byte(goConfig), 0600) + err = os.WriteFile(goConfigPath, []byte(goConfig), dirPermission) pythonConfigPath := filepath.Join(configFolderName, pb.Sdk_SDK_PYTHON.String()+jsonExt) - err = os.WriteFile(pythonConfigPath, []byte(pythonConfig), 0600) + err = os.WriteFile(pythonConfigPath, []byte(pythonConfig), dirPermission) scioConfigPath := filepath.Join(configFolderName, pb.Sdk_SDK_SCIO.String()+jsonExt) - err = os.WriteFile(scioConfigPath, []byte(scioConfig), 0600) + err = os.WriteFile(scioConfigPath, []byte(scioConfig), dirPermission) if err != nil { return err } @@ -416,19 +417,19 @@ func TestConfigureBeamEnvs(t *testing.T) { envsToSet: map[string]string{beamSdkKey: "SDK_SCIO"}, }, { - name: "NumOfParallelJobsKey is set with with a positive number", + name: "NumOfParallelJobsKey is set with a positive number", want: NewBeamEnvs(pb.Sdk_SDK_PYTHON, pythonExecutorConfig, modDir, 1), wantErr: false, envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON", numOfParallelJobsKey: "1"}, }, { - name: "NumOfParallelJobsKey is set with with a negative number", + name: "NumOfParallelJobsKey is set with a negative number", want: NewBeamEnvs(pb.Sdk_SDK_PYTHON, pythonExecutorConfig, modDir, defaultNumOfParallelJobs), wantErr: false, envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON", numOfParallelJobsKey: "-1"}, }, { - name: "NumOfParallelJobsKey is set with with incorrect value", + name: "NumOfParallelJobsKey is set with incorrect value", want: NewBeamEnvs(pb.Sdk_SDK_PYTHON, pythonExecutorConfig, modDir, defaultNumOfParallelJobs), wantErr: false, envsToSet: map[string]string{beamSdkKey: "SDK_PYTHON", numOfParallelJobsKey: "incorrectValue"}, From 1f1bf24541b8b2ee8ac390e9dbe8a4d0e040ab5e Mon Sep 17 00:00:00 2001 From: Pavel Avilov Date: Tue, 1 Mar 2022 17:59:46 +0300 Subject: [PATCH 4/4] Add bucket name to method --- .../internal/environment/environment_service_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/playground/backend/internal/environment/environment_service_test.go b/playground/backend/internal/environment/environment_service_test.go index f5d957626ad4d..3008e4fa8ffc6 100644 --- a/playground/backend/internal/environment/environment_service_test.go +++ b/playground/backend/internal/environment/environment_service_test.go @@ -234,25 +234,25 @@ func Test_getApplicationEnvsFromOsEnvs(t *testing.T) { }, { name: "CacheKeyExpirationTimeKey is set with the correct value", - want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, convertedTime}, defaultPipelineExecuteTimeout), + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, convertedTime}, defaultPipelineExecuteTimeout, defaultBucketName), wantErr: false, envsToSet: map[string]string{workingDirKey: "/app", cacheKeyExpirationTimeKey: hour}, }, { name: "CacheKeyExpirationTimeKey is set with the incorrect value", - want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout), + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout, defaultBucketName), wantErr: false, envsToSet: map[string]string{workingDirKey: "/app", cacheKeyExpirationTimeKey: "1"}, }, { name: "CacheKeyExpirationTimeKey is set with the correct value", - want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, convertedTime), + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, convertedTime, defaultBucketName), wantErr: false, envsToSet: map[string]string{workingDirKey: "/app", pipelineExecuteTimeoutKey: hour}, }, { name: "PipelineExecuteTimeoutKey is set with the incorrect value", - want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout), + want: NewApplicationEnvs("/app", defaultLaunchSite, defaultProjectId, defaultPipelinesFolder, &CacheEnvs{defaultCacheType, defaultCacheAddress, defaultCacheKeyExpirationTime}, defaultPipelineExecuteTimeout, defaultBucketName), wantErr: false, envsToSet: map[string]string{workingDirKey: "/app", pipelineExecuteTimeoutKey: "1"}, },