Skip to content

Commit

Permalink
Merge pull request #160 from planetscale/add-region-data-imports
Browse files Browse the repository at this point in the history
Add region to StartDataImport request type
  • Loading branch information
Phani Raj authored Apr 19, 2023
2 parents 0e67fbe + 599be2c commit ecff34e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion planetscale/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type DataImportSource struct {
SSLVerificationMode ExternalDataSourceSSLVerificationMode
UserName string `json:"username"`
Password string `json:"password"`
SSLCA string `json:"ssl_ca"`
SSLCertificate string `json:"ssl_cert"`
SSLKey string `json:"ssl_key"`
SSLServerName string `json:"ssl_server_name"`
}

type ExternalDataSourceSSLVerificationMode int
Expand Down Expand Up @@ -173,13 +177,16 @@ type TestDataImportSourceResponse struct {
SuggestedBillingPlan BillingPlan
ConnectError string `json:"error"`
Errors []*DataSourceIncompatibilityError `json:"lint_errors"`
MaxPoolSize int `json:"max_pool_size"`
}

type StartDataImportRequest struct {
Database string `json:"database_name"`
Organization string `json:"organization"`
Database string `json:"database_name"`
Connection DataImportSource `json:"connection"`
Region string `json:"region"`
Plan string `json:"plan"`
MaxPoolSize int `json:"max_pool_size"`
}

type MakePlanetScalePrimaryRequest struct {
Expand Down
10 changes: 9 additions & 1 deletion planetscale/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package planetscale

import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -99,6 +100,7 @@ func TestImports_CanRunLintExternalDatabase_LintFailure(t *testing.T) {
c := qt.New(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.Assert(r.URL.Path, qt.Equals, "/v1/organizations/my-org/data-imports/test-connection")

w.WriteHeader(200)
out := `{
"can_connect": true,
Expand Down Expand Up @@ -175,6 +177,11 @@ func TestImports_CanStartDataImport_Success(t *testing.T) {
c := qt.New(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.Assert(r.URL.Path, qt.Equals, "/v1/organizations/my-org/data-imports/new")
var startRequest StartDataImportRequest
err := json.NewDecoder(r.Body).Decode(&startRequest)
c.Assert(err, qt.IsNil)
c.Assert("us-west-2", qt.Equals, startRequest.Region)

w.WriteHeader(200)
out := `{
"id": "PUBLIC_ID",
Expand All @@ -186,7 +193,7 @@ func TestImports_CanStartDataImport_Success(t *testing.T) {
"database": "employees"
}
}`
_, err := w.Write([]byte(out))
_, err = w.Write([]byte(out))
c.Assert(err, qt.IsNil)
}))

Expand All @@ -199,6 +206,7 @@ func TestImports_CanStartDataImport_Success(t *testing.T) {
startReq := &StartDataImportRequest{
Organization: org,
Database: db,
Region: "us-west-2",
}
di, err := client.DataImports.StartDataImport(ctx, startReq)
c.Assert(err, qt.IsNil)
Expand Down

0 comments on commit ecff34e

Please sign in to comment.