• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 15583807449

11 Jun 2025 11:36AM UTC coverage: 55.106% (+0.02%) from 55.086%
15583807449

Pull #3680

github

web-flow
Merge ecceb62b8 into 06aaa3fcf
Pull Request #3680: feat: add restart command

42 of 65 new or added lines in 4 files covered. (64.62%)

10 existing lines in 3 files now uncovered.

6017 of 10919 relevant lines covered (55.11%)

6.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.36
/internal/testing/apitest/docker.go
1
package apitest
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "net/http"
7

8
        "github.com/docker/docker/api"
9
        "github.com/docker/docker/api/types/container"
10
        "github.com/docker/docker/api/types/image"
11
        "github.com/docker/docker/api/types/network"
12
        "github.com/docker/docker/api/types/versions"
13
        "github.com/docker/docker/api/types/volume"
14
        "github.com/docker/docker/client"
15
        "github.com/docker/docker/pkg/stdcopy"
16
        "github.com/go-errors/errors"
17
        "github.com/h2non/gock"
18
)
19

20
const mockHost = "http://127.0.0.1"
21

22
func MockDocker(docker *client.Client) error {
99✔
23
        // Skip setup if docker is already mocked
99✔
24
        if docker.DaemonHost() == mockHost {
179✔
25
                return nil
80✔
26
        }
80✔
27
        if err := client.WithVersion(api.DefaultVersion)(docker); err != nil {
19✔
28
                return err
×
29
        }
×
30
        // Safe to ignore errors as transport will be replaced by gock
31
        _ = client.WithHost(mockHost)(docker)
19✔
32
        return client.WithHTTPClient(http.DefaultClient)(docker)
19✔
33
}
34

35
// Ref: internal/utils/docker.go::DockerStart
36
func MockDockerStart(docker *client.Client, imageID, containerID string) {
75✔
37
        gock.New(docker.DaemonHost()).
75✔
38
                Get("/v" + docker.ClientVersion() + "/images/" + imageID + "/json").
75✔
39
                Reply(http.StatusOK).
75✔
40
                JSON(image.InspectResponse{})
75✔
41
        gock.New(docker.DaemonHost()).
75✔
42
                Post("/v" + docker.ClientVersion() + "/networks/create").
75✔
43
                Reply(http.StatusCreated).
75✔
44
                JSON(network.CreateResponse{})
75✔
45
        gock.New(docker.DaemonHost()).
75✔
46
                Post("/v" + docker.ClientVersion() + "/volumes/create").
75✔
47
                Persist().
75✔
48
                Reply(http.StatusCreated).
75✔
49
                JSON(volume.Volume{})
75✔
50
        gock.New(docker.DaemonHost()).
75✔
51
                Post("/v" + docker.ClientVersion() + "/containers/create").
75✔
52
                Reply(http.StatusOK).
75✔
53
                JSON(container.CreateResponse{ID: containerID})
75✔
54
        gock.New(docker.DaemonHost()).
75✔
55
                Post("/v" + docker.ClientVersion() + "/containers/" + containerID + "/start").
75✔
56
                Reply(http.StatusAccepted)
75✔
57
}
75✔
58

59
// Ref: internal/utils/docker.go::DockerRemoveAll
60
func MockDockerStop(docker *client.Client) {
3✔
61
        gock.New(docker.DaemonHost()).
3✔
62
                Get("/v" + docker.ClientVersion() + "/containers/json").
3✔
63
                Reply(http.StatusOK).
3✔
64
                JSON([]container.Summary{})
3✔
65
        gock.New(docker.DaemonHost()).
3✔
66
                Post("/v" + docker.ClientVersion() + "/containers/prune").
3✔
67
                Reply(http.StatusOK).
3✔
68
                JSON(container.PruneReport{})
3✔
69
        if !versions.GreaterThanOrEqualTo(docker.ClientVersion(), "1.42") {
4✔
70
                gock.New(docker.DaemonHost()).
1✔
71
                        Post("/v"+docker.ClientVersion()+"/volumes/prune").
1✔
72
                        MatchParam("filters", `"all":{"true":true}`).
1✔
73
                        ReplyError(errors.New(`failed to parse filters for all=true&label=com.supabase.cli.project%3Dtest: "all" is an invalid volume filter`))
1✔
74
        }
1✔
75
        gock.New(docker.DaemonHost()).
3✔
76
                Post("/v" + docker.ClientVersion() + "/volumes/prune").
3✔
77
                Reply(http.StatusOK).
3✔
78
                JSON(volume.PruneReport{})
3✔
79
        gock.New(docker.DaemonHost()).
3✔
80
                Post("/v" + docker.ClientVersion() + "/networks/prune").
3✔
81
                Reply(http.StatusOK).
3✔
82
                JSON(network.PruneReport{})
3✔
83
}
84

85
// Ref: internal/utils/docker.go::DockerRestartAll
NEW
86
func MockDockerRestart(docker *client.Client) {
×
NEW
87
        gock.New(docker.DaemonHost()).
×
NEW
88
                Get("/v" + docker.ClientVersion() + "/containers/json").
×
NEW
89
                Reply(http.StatusOK).
×
NEW
90
                JSON([]container.Summary{})
×
NEW
91
}
×
92

93
// Ref: internal/utils/docker.go::DockerRunOnce
94
func setupDockerLogs(docker *client.Client, containerID, stdout string, exitCode int) error {
44✔
95
        var body bytes.Buffer
44✔
96
        writer := stdcopy.NewStdWriter(&body, stdcopy.Stdout)
44✔
97
        _, err := writer.Write([]byte(stdout))
44✔
98
        gock.New(docker.DaemonHost()).
44✔
99
                Get("/v"+docker.ClientVersion()+"/containers/"+containerID+"/logs").
44✔
100
                Reply(http.StatusOK).
44✔
101
                SetHeader("Content-Type", "application/vnd.docker.raw-stream").
44✔
102
                Body(&body)
44✔
103
        gock.New(docker.DaemonHost()).
44✔
104
                Get("/v" + docker.ClientVersion() + "/containers/" + containerID + "/json").
44✔
105
                Reply(http.StatusOK).
44✔
106
                JSON(container.InspectResponse{ContainerJSONBase: &container.ContainerJSONBase{
44✔
107
                        State: &container.State{
44✔
108
                                ExitCode: exitCode,
44✔
109
                        }}})
44✔
110
        gock.New(docker.DaemonHost()).
44✔
111
                Delete("/v" + docker.ClientVersion() + "/containers/" + containerID).
44✔
112
                Reply(http.StatusOK)
44✔
113
        return err
44✔
114
}
44✔
115

116
func MockDockerLogs(docker *client.Client, containerID, stdout string) error {
43✔
117
        return setupDockerLogs(docker, containerID, stdout, 0)
43✔
118
}
43✔
119

120
func MockDockerLogsExitCode(docker *client.Client, containerID string, exitCode int) error {
1✔
121
        return setupDockerLogs(docker, containerID, "", exitCode)
1✔
122
}
1✔
123

124
func ListUnmatchedRequests() []string {
240✔
125
        result := make([]string, len(gock.GetUnmatchedRequests()))
240✔
126
        for i, r := range gock.GetUnmatchedRequests() {
240✔
127
                result[i] = fmt.Sprintln(r.Method, r.URL.Path)
×
128
        }
×
129
        return result
240✔
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc