-
Notifications
You must be signed in to change notification settings - Fork 23
REALMC-9363 - Removed client-side transpilation. #178
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
Changes from all commits
6067b28
f0350b2
02393e5
1196194
2b5b295
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,44 @@ const ( | |
| dependenciesPathPattern = appPathPattern + "/dependencies" | ||
| dependenciesArchivePathPattern = dependenciesPathPattern + "/archive" | ||
| dependenciesDiffPathPattern = dependenciesPathPattern + "/diff" | ||
| dependenciesStatusPathPattern = dependenciesPathPattern + "/status" | ||
|
|
||
| paramFile = "file" | ||
| ) | ||
|
|
||
| // DependenciesStatus is used to get information from a dependencies status request | ||
| type DependenciesStatus struct { | ||
| State string `json:"status"` | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may be the best way to avoid stutter but I can see how the idea of a State of Status is a bit odd. |
||
| Message string `json:"status_message"` | ||
| } | ||
|
|
||
| // set of known dependencies status states | ||
| const ( | ||
| DependenciesStateCreated = "created" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated these to make them more related to the |
||
| DependenciesStateSuccessful = "successful" | ||
| DependenciesStateFailed = "failed" | ||
| ) | ||
|
|
||
| func (c *client) DependenciesStatus(groupID, appID string) (DependenciesStatus, error) { | ||
| res, err := c.do( | ||
| http.MethodGet, | ||
| fmt.Sprintf(dependenciesStatusPathPattern, groupID, appID), | ||
| api.RequestOptions{}, | ||
| ) | ||
| if err != nil { | ||
| return DependenciesStatus{}, err | ||
| } | ||
| if res.StatusCode != http.StatusOK { | ||
| return DependenciesStatus{}, api.ErrUnexpectedStatusCode{"get dependencies status", res.StatusCode} | ||
| } | ||
gagik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| defer res.Body.Close() | ||
| var status DependenciesStatus | ||
| if err := json.NewDecoder(res.Body).Decode(&status); err != nil { | ||
| return DependenciesStatus{}, err | ||
| } | ||
| return status, nil | ||
| } | ||
|
|
||
| func (c *client) ImportDependencies(groupID, appID, uploadPath string) error { | ||
| file, fileErr := os.Open(uploadPath) | ||
| if fileErr != nil { | ||
|
|
@@ -37,9 +71,9 @@ func (c *client) ImportDependencies(groupID, appID, uploadPath string) error { | |
| body := &bytes.Buffer{} | ||
| w := multipart.NewWriter(body) | ||
|
|
||
| form, formErr := w.CreateFormFile(paramFile, fileInfo.Name()) | ||
| if formErr != nil { | ||
| return formErr | ||
| form, err := w.CreateFormFile(paramFile, fileInfo.Name()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if _, err := io.Copy(form, file); err != nil { | ||
|
|
@@ -49,20 +83,21 @@ func (c *client) ImportDependencies(groupID, appID, uploadPath string) error { | |
| return err | ||
| } | ||
|
|
||
| res, resErr := c.do( | ||
| http.MethodPost, | ||
| res, err := c.do( | ||
| http.MethodPut, | ||
makesitgo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fmt.Sprintf(dependenciesPathPattern, groupID, appID), | ||
| api.RequestOptions{ | ||
| Body: body, | ||
| ContentType: w.FormDataContentType(), | ||
| }, | ||
| ) | ||
| if resErr != nil { | ||
| return resErr | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if res.StatusCode != http.StatusNoContent { | ||
| return api.ErrUnexpectedStatusCode{"import dependencies", res.StatusCode} | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,32 @@ func TestRealmDependencies(t *testing.T) { | |
| assert.Nil(t, err) | ||
|
|
||
| uploadPath := filepath.Join(wd, "testdata/dependencies_upload.zip") | ||
|
|
||
| _, err = client.DependenciesStatus(groupID, app.ID) | ||
| assert.Equal(t, realm.ServerError{Message: "dependency installation not found"}, err) | ||
|
|
||
| assert.Nil(t, client.ImportDependencies(groupID, app.ID, uploadPath)) | ||
|
|
||
| startStatus, err := client.DependenciesStatus(groupID, app.ID) | ||
| assert.Nil(t, err) | ||
gagik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.Equal(t, realm.DependenciesStatus{ | ||
| State: realm.DependenciesStateCreated, | ||
| Message: "processing request", | ||
| }, startStatus) | ||
|
|
||
| // wait for dependencies to finish installation | ||
| var currentStatus realm.DependenciesStatus | ||
| for i := 0; i < 50; i++ { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in my computer it usually takes around <15 runs but I imagine with all sorts of delays and all, |
||
| var err error | ||
| currentStatus, err = client.DependenciesStatus(groupID, app.ID) | ||
| assert.Nil(t, err) | ||
| if currentStatus.State != realm.DependenciesStateCreated { | ||
| break | ||
| } | ||
| time.Sleep(time.Second) | ||
| } | ||
| assert.Equal(t, realm.DependenciesStateSuccessful, currentStatus.State) | ||
|
|
||
| t.Run("and wait for those dependencies to be deployed to the app", func(t *testing.T) { | ||
| deployments, err := client.Deployments(groupID, app.ID) | ||
| assert.Nil(t, err) | ||
|
|
@@ -78,7 +102,8 @@ func TestRealmDependencies(t *testing.T) { | |
| assert.Nil(t, expectedDepsErr) | ||
| defer expectedDeps.Close() | ||
|
|
||
| assert.Equalf(t, parseZipArchive(t, expectedDeps), parseZipArchive(t, actualDeps), "expected archives to match") | ||
| // make sure same files are present; contents may be different because of transpilation | ||
gagik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.Equal(t, getZipFileNames(t, expectedDeps), getZipFileNames(t, actualDeps)) | ||
| }) | ||
| }) | ||
|
|
||
|
|
@@ -97,7 +122,7 @@ func TestRealmDependencies(t *testing.T) { | |
| }) | ||
| } | ||
|
|
||
| func parseZipArchive(t *testing.T, file *os.File) map[string]string { | ||
| func getZipFileNames(t *testing.T, file *os.File) map[string]struct{} { | ||
| t.Helper() | ||
|
|
||
| fileInfo, err := file.Stat() | ||
|
|
@@ -106,5 +131,13 @@ func parseZipArchive(t *testing.T, file *os.File) map[string]string { | |
| zipPkg, err := zip.NewReader(file, fileInfo.Size()) | ||
| assert.Nil(t, err) | ||
|
|
||
| return parseZipPkg(t, zipPkg) | ||
| out := make(map[string]struct{}, len(zipPkg.File)) | ||
|
|
||
| for _, file := range zipPkg.File { | ||
| if file.FileInfo().IsDir() { | ||
| continue | ||
| } | ||
| out[file.Name] = struct{}{} | ||
| } | ||
| return out | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.