fix: removes deprecated code (#2730)

This commit is contained in:
Amir Raminfar
2024-01-24 09:48:29 -08:00
committed by GitHub
parent 808abd57bb
commit ef636c86fc
9 changed files with 26 additions and 29 deletions
+4
View File
@@ -60,6 +60,10 @@ jobs:
uses: actions/checkout@v4
- name: Run Go Tests with Coverage
run: make test SKIP_ASSET=1
- name: Stactic checker
uses: dominikh/staticcheck-action@v1.3.0
with:
install-go: false
int-test:
name: Integration Tests
timeout-minutes: 60
+7 -7
View File
@@ -44,13 +44,13 @@ func (s StdType) String() string {
}
type DockerCLI interface {
ContainerList(context.Context, types.ContainerListOptions) ([]types.Container, error)
ContainerLogs(context.Context, string, types.ContainerLogsOptions) (io.ReadCloser, error)
ContainerList(context.Context, container.ListOptions) ([]types.Container, error)
ContainerLogs(context.Context, string, container.LogsOptions) (io.ReadCloser, error)
Events(context.Context, types.EventsOptions) (<-chan events.Message, <-chan error)
ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error)
Ping(ctx context.Context) (types.Ping, error)
ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error
ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error
ContainerRestart(ctx context.Context, containerID string, options container.StopOptions) error
}
@@ -152,7 +152,7 @@ func (d *Client) FindContainer(id string) (Container, error) {
func (d *Client) ContainerActions(action string, containerID string) error {
switch action {
case "start":
return d.cli.ContainerStart(context.Background(), containerID, types.ContainerStartOptions{})
return d.cli.ContainerStart(context.Background(), containerID, container.StartOptions{})
case "stop":
return d.cli.ContainerStop(context.Background(), containerID, container.StopOptions{})
case "restart":
@@ -163,7 +163,7 @@ func (d *Client) ContainerActions(action string, containerID string) error {
}
func (d *Client) ListContainers() ([]Container, error) {
containerListOptions := types.ContainerListOptions{
containerListOptions := container.ListOptions{
Filters: d.filters,
All: true,
}
@@ -274,7 +274,7 @@ func (d *Client) ContainerLogs(ctx context.Context, id string, since string, std
}
}
options := types.ContainerLogsOptions{
options := container.LogsOptions{
ShowStdout: stdType&STDOUT != 0,
ShowStderr: stdType&STDERR != 0,
Follow: true,
@@ -320,7 +320,7 @@ func (d *Client) Events(ctx context.Context, messages chan<- ContainerEvent) <-c
}
func (d *Client) ContainerLogsBetweenDates(ctx context.Context, id string, from time.Time, to time.Time, stdType StdType) (io.ReadCloser, error) {
options := types.ContainerLogsOptions{
options := container.LogsOptions{
ShowStdout: stdType&STDOUT != 0,
ShowStderr: stdType&STDERR != 0,
Timestamps: true,
+4 -4
View File
@@ -22,7 +22,7 @@ type mockedProxy struct {
DockerCLI
}
func (m *mockedProxy) ContainerList(context.Context, types.ContainerListOptions) ([]types.Container, error) {
func (m *mockedProxy) ContainerList(context.Context, container.ListOptions) ([]types.Container, error) {
args := m.Called()
containers, ok := args.Get(0).([]types.Container)
if !ok && args.Get(0) != nil {
@@ -32,7 +32,7 @@ func (m *mockedProxy) ContainerList(context.Context, types.ContainerListOptions)
}
func (m *mockedProxy) ContainerLogs(ctx context.Context, id string, options types.ContainerLogsOptions) (io.ReadCloser, error) {
func (m *mockedProxy) ContainerLogs(ctx context.Context, id string, options container.LogsOptions) (io.ReadCloser, error) {
args := m.Called(ctx, id, options)
reader, ok := args.Get(0).(io.ReadCloser)
if !ok && args.Get(0) != nil {
@@ -50,7 +50,7 @@ func (m *mockedProxy) ContainerStats(ctx context.Context, containerID string, st
return types.ContainerStats{}, nil
}
func (m *mockedProxy) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error {
func (m *mockedProxy) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error {
args := m.Called(ctx, containerID, options)
err := args.Get(0)
@@ -158,7 +158,7 @@ func Test_dockerClient_ContainerLogs_happy(t *testing.T) {
b = append(b, []byte(expected)...)
reader := io.NopCloser(bytes.NewReader(b))
options := types.ContainerLogsOptions{ShowStdout: true, ShowStderr: true, Follow: true, Tail: "300", Timestamps: true, Since: "since"}
options := container.LogsOptions{ShowStdout: true, ShowStderr: true, Follow: true, Tail: "300", Timestamps: true, Since: "since"}
proxy.On("ContainerLogs", mock.Anything, id, options).Return(reader, nil)
client := &Client{proxy, filters.NewArgs(), &Host{ID: "localhost"}}
+1 -1
View File
@@ -193,7 +193,7 @@ func createEvent(message string, streamType StdType) *LogEvent {
for decoder.ScanKeyval() {
key := decoder.Key()
value := decoder.Value()
if validLogFmtKey.Match(key) == false {
if !validLogFmtKey.Match(key) {
allValid = false
break
}
+1 -2
View File
@@ -81,8 +81,7 @@ func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
func Test_createEvent(t *testing.T) {
type args struct {
message string
streamType StdType
message string
}
tests := []struct {
name string
+1 -1
View File
@@ -35,5 +35,5 @@ func HttpRequest(addr string, base string) error {
return nil
}
return fmt.Errorf("Healthcheck failed with status code %d", resp.StatusCode)
return fmt.Errorf("healthcheck failed with status code %d", resp.StatusCode)
}
+3 -3
View File
@@ -17,7 +17,7 @@ const (
profileFilename = "profile.json"
)
var missingProfileErr = errors.New("Profile file does not exist")
var errMissingProfileErr = errors.New("Profile file does not exist")
type Settings struct {
Search bool `json:"search"`
@@ -66,7 +66,7 @@ func UpdateFromReader(user auth.User, reader io.Reader) error {
mux.Lock()
defer mux.Unlock()
existingProfile, err := Load(user)
if err != nil && err != missingProfileErr {
if err != nil && err != errMissingProfileErr {
return err
}
@@ -112,7 +112,7 @@ func Load(user auth.User) (Profile, error) {
profilePath := filepath.Join(path, profileFilename)
if _, err := os.Stat(profilePath); os.IsNotExist(err) {
return Profile{}, missingProfileErr
return Profile{}, errMissingProfileErr
}
f, err := os.Open(profilePath)
+3 -10
View File
@@ -85,16 +85,9 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
g := docker.NewEventGenerator(reader, container.Tty)
encoder := json.NewEncoder(w)
loop:
for {
select {
case event, ok := <-g.Events:
if !ok {
break loop
}
if err := encoder.Encode(event); err != nil {
log.Errorf("json encoding error while streaming %v", err.Error())
}
for event := range g.Events {
if err := encoder.Encode(event); err != nil {
log.Errorf("json encoding error while streaming %v", err.Error())
}
}
}
+2 -1
View File
@@ -7,6 +7,7 @@ import (
"github.com/amir20/dozzle/internal/docker"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
@@ -17,7 +18,7 @@ type fakeCLI struct {
mock.Mock
}
func (f *fakeCLI) ContainerList(context.Context, types.ContainerListOptions) ([]types.Container, error) {
func (f *fakeCLI) ContainerList(context.Context, container.ListOptions) ([]types.Container, error) {
args := f.Called()
return args.Get(0).([]types.Container), args.Error(1)
}