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

Specify aws in region request when creating a deployment #1403

Merged
merged 2 commits into from
Oct 2, 2023
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
4 changes: 4 additions & 0 deletions cloud/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
CeleryExecutor = "CeleryExecutor"
notApplicable = "N/A"
gcpCloud = "gcp"
awsCloud = "aws"
standard = "standard"
)

Expand Down Expand Up @@ -414,6 +415,9 @@ func ListClusterOptions(cloudProvider string, coreClient astrocore.CoreClient) (
if cloudProvider == gcpCloud {
provider = astrocore.GetClusterOptionsParamsProvider(astrocore.GetClusterOptionsParamsProviderGcp) //nolint
}
if cloudProvider == awsCloud {
provider = astrocore.GetClusterOptionsParamsProvider(astrocore.GetClusterOptionsParamsProviderAws) //nolint
}
optionsParams := &astrocore.GetClusterOptionsParams{
Provider: &provider,
Type: astrocore.GetClusterOptionsParamsType(astrocore.GetClusterOptionsParamsTypeSHARED), //nolint
Expand Down
39 changes: 39 additions & 0 deletions cloud/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,45 @@ func TestSelectRegion(t *testing.T) {
assert.Equal(t, region, resp)
})

t.Run("region via selection aws", func(t *testing.T) {
provider := astrocore.GetClusterOptionsParamsProvider(astrocore.GetClusterOptionsParamsProviderAws) //nolint
getSharedClusterOptionsParams := &astrocore.GetClusterOptionsParams{
Provider: &provider,
Type: astrocore.GetClusterOptionsParamsType(astrocore.GetClusterOptionsParamsTypeSHARED), //nolint
}

mockOKRegionResponse := &astrocore.GetClusterOptionsResponse{
HTTPResponse: &http.Response{
StatusCode: 200,
},
JSON200: &[]astrocore.ClusterOptions{
{Regions: []astrocore.ProviderRegion{{Name: region}}},
},
}

mockCoreClient.On("GetClusterOptionsWithResponse", mock.Anything, getSharedClusterOptionsParams).Return(mockOKRegionResponse, nil).Once()

// mock os.Stdin
input := []byte("1")
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
_, err = w.Write(input)
if err != nil {
t.Error(err)
}
w.Close()
stdin := os.Stdin
// Restore stdin right after the test.
defer func() { os.Stdin = stdin }()
os.Stdin = r

resp, err := selectRegion("aws", "", mockCoreClient)
assert.NoError(t, err)
assert.Equal(t, region, resp)
})

t.Run("region invalid selection", func(t *testing.T) {
provider := astrocore.GetClusterOptionsParamsProvider(astrocore.GetClusterOptionsParamsProviderGcp) //nolint
getSharedClusterOptionsParams := &astrocore.GetClusterOptionsParams{
Expand Down