mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package web
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"io"
|
|
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/amir20/dozzle/internal/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/hosts/localhost/containers/"+id+"/logs/download?stdout=1", 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.STDOUT).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)
|
|
}
|