Skip to content

Commit

Permalink
fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Jan 3, 2025
1 parent 4b4327c commit 81c50cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 56 deletions.
64 changes: 14 additions & 50 deletions internal/web/__snapshots__/web.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,15 @@ Content-Type: text/html
<pre>dev</pre>

/* snapshot: Test_handler_between_dates */
HTTP/1.1 200 OK
Connection: close
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
Content-Type: application/x-jsonl; charset=UTF-8

{"m":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"}
{"m":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"}


/* snapshot: Test_handler_between_dates_with_fill */
HTTP/1.1 200 OK
Connection: close
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
Content-Type: application/x-jsonl; charset=UTF-8

{"m":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"}
{"m":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"}


/* snapshot: Test_handler_download_logs */
INFO Testing logs...

Expand Down Expand Up @@ -157,16 +149,9 @@ X-Content-Type-Options: nosniff
error finding container

/* snapshot: Test_handler_streamLogs_error_reading */
HTTP/1.1 200 OK
Connection: close
Cache-Control: no-transform
Cache-Control: no-cache
Connection: keep-alive
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
Content-Type: text/event-stream
X-Accel-Buffering: no

:ping
:ping



/* snapshot: Test_handler_streamLogs_error_std */
HTTP/1.1 400 Bad Request
Expand All @@ -178,53 +163,32 @@ X-Content-Type-Options: nosniff
stdout or stderr is required

/* snapshot: Test_handler_streamLogs_happy */
HTTP/1.1 200 OK
Connection: close
Cache-Control: no-transform
Cache-Control: no-cache
Connection: keep-alive
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
Content-Type: text/event-stream
X-Accel-Buffering: no

:ping

data: {"m":"INFO Testing logs...","ts":0,"id":4256192898,"l":"info","s":"stdout","c":"123456"}


event: container-event
data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"2025-01-03T10:52:34.003134-08:00"}
data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"<removed>"}




/* snapshot: Test_handler_streamLogs_happy_container_stopped */
HTTP/1.1 200 OK
Connection: close
Cache-Control: no-transform
Cache-Control: no-cache
Connection: keep-alive
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
Content-Type: text/event-stream
X-Accel-Buffering: no

:ping

event: container-event
data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"2025-01-03T10:52:34.109992-08:00"}
data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"<removed>"}




/* snapshot: Test_handler_streamLogs_happy_with_id */
HTTP/1.1 200 OK
Connection: close
Cache-Control: no-transform
Cache-Control: no-cache
Connection: keep-alive
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
Content-Type: text/event-stream
X-Accel-Buffering: no

:ping

data: {"m":"INFO Testing logs...","ts":1589396137772,"id":1469707724,"l":"info","s":"stdout","c":"123456"}
id: 1589396137772


event: container-event
data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"2025-01-03T10:52:34.056228-08:00"}
data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"<removed>"}
19 changes: 13 additions & 6 deletions internal/web/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/binary"
"errors"
"io"
"regexp"
"time"

"net/http"
Expand Down Expand Up @@ -60,7 +61,8 @@ func Test_handler_streamLogs_happy(t *testing.T) {
handler := createDefaultHandler(mockedClient)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
reader := strings.NewReader(regexp.MustCompile(`"time":"[^"]*"`).ReplaceAllString(rr.Body.String(), `"time":"<removed>"`))
abide.AssertReader(t, t.Name(), reader)
mockedClient.AssertExpectations(t)
}

Expand Down Expand Up @@ -105,7 +107,8 @@ func Test_handler_streamLogs_happy_with_id(t *testing.T) {
handler := createDefaultHandler(mockedClient)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
reader := strings.NewReader(regexp.MustCompile(`"time":"[^"]*"`).ReplaceAllString(rr.Body.String(), `"time":"<removed>"`))
abide.AssertReader(t, t.Name(), reader)
mockedClient.AssertExpectations(t)
}

Expand Down Expand Up @@ -141,7 +144,8 @@ func Test_handler_streamLogs_happy_container_stopped(t *testing.T) {
handler := createDefaultHandler(mockedClient)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
reader := strings.NewReader(regexp.MustCompile(`"time":"[^"]*"`).ReplaceAllString(rr.Body.String(), `"time":"<removed>"`))
abide.AssertReader(t, t.Name(), reader)
mockedClient.AssertExpectations(t)
}

Expand Down Expand Up @@ -178,7 +182,8 @@ func Test_handler_streamLogs_error_reading(t *testing.T) {
handler := createDefaultHandler(mockedClient)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
reader := strings.NewReader(regexp.MustCompile(`"time":"[^"]*"`).ReplaceAllString(rr.Body.String(), `"time":"<removed>"`))
abide.AssertReader(t, t.Name(), reader)
mockedClient.AssertExpectations(t)
}

Expand Down Expand Up @@ -243,7 +248,8 @@ func Test_handler_between_dates(t *testing.T) {
handler := createDefaultHandler(mockedClient)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
reader := strings.NewReader(regexp.MustCompile(`"time":"[^"]*"`).ReplaceAllString(rr.Body.String(), `"time":"<removed>"`))
abide.AssertReader(t, t.Name(), reader)
mockedClient.AssertExpectations(t)
}

Expand Down Expand Up @@ -289,7 +295,8 @@ func Test_handler_between_dates_with_fill(t *testing.T) {
handler := createDefaultHandler(mockedClient)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
reader := strings.NewReader(regexp.MustCompile(`"time":"[^"]*"`).ReplaceAllString(rr.Body.String(), `"time":"<removed>"`))
abide.AssertReader(t, t.Name(), reader)
mockedClient.AssertExpectations(t)
}

Expand Down

0 comments on commit 81c50cb

Please sign in to comment.