Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-13873] [Playground] Increase test coverage for the environment package #16946

Merged
merged 5 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions playground/backend/internal/environment/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand All @@ -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: "Get server protocol",
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)
}
})
}
}
41 changes: 40 additions & 1 deletion playground/backend/internal/environment/beam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: "Get the number of parallel jobs",
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)
}
})
}
}
Loading