1
0
mirror of https://github.com/amir20/dozzle.git synced 2026-01-03 19:45:01 +01:00
Files
dozzle/web/routes_download_test.go
Amir Raminfar 1bb1081f1a fix(performance): improves streaming of logs by using the Docker library to demultiplex (#2295)
* fix(performance): improves streaming of logs by using the Docker library to demultiplex

* fixes go tests

* changes channel to unbuffered

* fixes golang race test

* fixes stopped containers

* wip

* uses different strategy

* cleans tests

* cleans tests

* adds more tests

* fixes possible bug

* fixes download

* adds more tests for download

* uses pool

* adds more tests
2023-07-11 09:52:30 -07:00

37 lines
1014 B
Go

package web
import (
"bytes"
"compress/gzip"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/amir20/dozzle/docker"
"github.com/beme/abide"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func Test_handler_download_logs(t *testing.T) {
id := "123456"
req, err := http.NewRequest("GET", "/api/logs/download/localhost/"+id, nil)
require.NoError(t, err, "NewRequest should not return an error.")
mockedClient := new(MockedClient)
data := makeMessage("INFO Testing logs...", docker.STDOUT)
mockedClient.On("FindContainer", id).Return(docker.Container{ID: id, Tty: false}, nil)
mockedClient.On("ContainerLogsBetweenDates", mock.Anything, id, mock.Anything, mock.Anything, docker.STDALL).Return(io.NopCloser(bytes.NewReader(data)), nil)
handler := createDefaultHandler(mockedClient)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
reader, _ := gzip.NewReader(rr.Body)
abide.AssertReader(t, t.Name(), reader)
mockedClient.AssertExpectations(t)
}