From 03eae11d12a714524b770d2fdda336676cc94557 Mon Sep 17 00:00:00 2001 From: Daniel Climent Date: Thu, 7 Sep 2023 15:51:11 +0200 Subject: [PATCH] wip --- go/porcelain/deploy.go | 1 + go/porcelain/deploy_test.go | 44 +++++++++---------------------------- swagger.yml | 6 ++--- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index ec27025b..2589d4fa 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -539,6 +539,7 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl if operationError != nil { context.GetLogger(ctx).WithError(operationError).Errorf("Failed to upload file %v", f.Name) + apiErr, ok := operationError.(apierrors.Error) if ok { diff --git a/go/porcelain/deploy_test.go b/go/porcelain/deploy_test.go index 32270f07..67e96b95 100644 --- a/go/porcelain/deploy_test.go +++ b/go/porcelain/deploy_test.go @@ -326,60 +326,36 @@ func TestUploadFiles400Error_SkipsRetry(t *testing.T) { ctx := gocontext.Background() server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { - defer func() { - attempts++ - }() + attempts++ - rw.WriteHeader(http.StatusUnprocessableEntity) rw.Header().Set("Content-Type", "application/json; charset=utf-8") + rw.WriteHeader(http.StatusUnprocessableEntity) rw.Write([]byte(`{"message": "Unprocessable Entity", "code": 422 }`)) })) defer server.Close() - // // File upload: - // hu, _ := url.Parse(server.URL) - // tr := apiClient.NewWithClient(hu.Host, "/api/v1", []string{"http"}, http.DefaultClient) - // client := NewRetryable(tr, strfmt.Default, 1) - // client.uploadLimit = 1 - // ctx = context.WithAuthInfo(ctx, apiClient.BearerToken("token")) - - // // Create some files to deploy - // dir, err := ioutil.TempDir("", "deploy") - // require.NoError(t, err) - // defer os.RemoveAll(dir) - // require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "foo.html"), []byte("Hello"), 0644)) - - // files, err := walk(dir, nil, false, false) - // require.NoError(t, err) - // d := &models.Deploy{} - // for _, bundle := range files.Files { - // d.Required = append(d.Required, bundle.Sum) - // } - // // Set SkipRetry to true - // err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute, true) - - // // Function upload: + // File upload: hu, _ := url.Parse(server.URL) tr := apiClient.NewWithClient(hu.Host, "/api/v1", []string{"http"}, http.DefaultClient) client := NewRetryable(tr, strfmt.Default, 1) client.uploadLimit = 1 - apiCtx := context.WithAuthInfo(ctx, apiClient.BearerToken("token")) + ctx = context.WithAuthInfo(ctx, apiClient.BearerToken("token")) + // Create some files to deploy dir, err := ioutil.TempDir("", "deploy") - functionsPath := filepath.Join(dir, ".netlify", "functions") - os.MkdirAll(functionsPath, os.ModePerm) require.NoError(t, err) defer os.RemoveAll(dir) - require.NoError(t, ioutil.WriteFile(filepath.Join(functionsPath, "foo.js"), []byte("module.exports = () => {}"), 0644)) + require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "foo.html"), []byte("Hello"), 0644)) - files, _, _, err := bundle(ctx, functionsPath, mockObserver{}) + files, err := walk(dir, nil, false, false) require.NoError(t, err) d := &models.Deploy{} for _, bundle := range files.Files { - d.RequiredFunctions = append(d.RequiredFunctions, bundle.Sum) + d.Required = append(d.Required, bundle.Sum) } // Set SkipRetry to true - require.NoError(t, client.uploadFiles(apiCtx, d, files, nil, functionUpload, time.Minute, true)) + err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute, true) + require.Equal(t, err, "[PUT /deploys/{deploy_id}/files/{path}][422] uploadDeployFile default &{Code:422 Message: Unprocessable Entity}") require.Equal(t, attempts, 1) } diff --git a/swagger.yml b/swagger.yml index e6fceb32..4da9c206 100644 --- a/swagger.yml +++ b/swagger.yml @@ -283,7 +283,7 @@ paths: is_secret: type: boolean description: >- - Secret values are only readable by code running on Netlify’s systems. + Secret values are only readable by code running on Netlify’s systems. With secrets, only the local development context values are readable from the UI, API, and CLI. By default, environment variable values are not secret. (Enterprise plans only) - name: account_id @@ -387,7 +387,7 @@ paths: is_secret: type: boolean description: >- - Secret values are only readable by code running on Netlify’s systems. + Secret values are only readable by code running on Netlify’s systems. With secrets, only the local development context values are readable from the UI, API, and CLI. By default, environment variable values are not secret. (Enterprise plans only) - name: site_id @@ -2737,7 +2737,7 @@ definitions: is_secret: type: boolean description: >- - Secret values are only readable by code running on Netlify’s systems. + Secret values are only readable by code running on Netlify’s systems. With secrets, only the local development context values are readable from the UI, API, and CLI. By default, environment variable values are not secret. (Enterprise plans only) updated_at: