From a73f0d5d0108e2e10d89f93c7867addbe073add9 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Wed, 22 Nov 2023 13:16:21 +0700 Subject: 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 --- http_server_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'http_server_test.go') 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 -- cgit v1.3