diff options
| author | Shulhan <ms@kilabit.info> | 2023-11-22 13:16:21 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-12-01 13:17:30 +0700 |
| commit | a73f0d5d0108e2e10d89f93c7867addbe073add9 (patch) | |
| tree | 042e69e2c1d10d836a006abca37417af02bba826 /http_server_test.go | |
| parent | a9701f66c2e38a3a7f3d12deed6ebba5144e208e (diff) | |
| download | awwan-a73f0d5d0108e2e10d89f93c7867addbe073add9.tar.xz | |
all: refactoring HTTP endpoint for Execute
Previously, the Execute endpoint wait for command execution to finish.
In case the command takes longer than proxy or server write timeout, it
will return with an timeout error to client.
In this changes, we generate an execution ID for each request and return
it immediately.
The next commit will implement HTTP endpoint to fetch the latest status
and/or output by execution ID.
References: https://todo.sr.ht/~shulhan/awwan/5
Diffstat (limited to 'http_server_test.go')
| -rw-r--r-- | http_server_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/http_server_test.go b/http_server_test.go index 81a8b61..93ba87f 100644 --- a/http_server_test.go +++ b/http_server_test.go @@ -191,6 +191,58 @@ func TestHttpServer_Encrypt(t *testing.T) { } } +func TestHttpServer_Execute(t *testing.T) { + var ( + tdata *test.Data + err error + ) + + tdata, err = test.LoadData(`testdata/http_server/execute/local_test.data`) + if err != nil { + t.Fatal(err) + } + + var aww *Awwan + + aww, err = New(`testdata/http_server/execute`) + if err != nil { + t.Fatal(err) + } + + var httpd *httpServer + + httpd, err = newHttpServer(aww, ``) + if err != nil { + t.Fatal(err) + } + + var buf bytes.Buffer + + buf.Write(tdata.Input[`local:/local.aww:1-`]) + + var ( + httpReq = httptest.NewRequest(http.MethodPost, pathAwwanApiExecute, &buf) + httpWriter = httptest.NewRecorder() + ) + + httpd.ServeHTTP(httpWriter, httpReq) + + var ( + httpRes = httpWriter.Result() + + resBody []byte + ) + + resBody, _ = io.ReadAll(httpRes.Body) + + buf.Reset() + json.Indent(&buf, resBody, ``, ` `) + + var expResp = string(tdata.Output[`local:/local.aww:1-`]) + + test.Assert(t, `First response`, expResp, buf.String()) +} + func TestHttpServer_FSGet(t *testing.T) { var ( tdata *test.Data |
