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

supabase / cli / 15540005669

09 Jun 2025 04:58PM UTC coverage: 55.168% (+0.1%) from 55.066%
15540005669

Pull #3243

github

web-flow
Merge c0d923396 into 7280a4611
Pull Request #3243: fix: automatically set default schema env var for type generation

44 of 48 new or added lines in 3 files covered. (91.67%)

5 existing lines in 1 file now uncovered.

6005 of 10885 relevant lines covered (55.17%)

6.2 hits per line

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

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

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

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

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

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

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

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

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

109
func MockDockerLogs(docker *client.Client, containerID, stdout string) error {
47✔
110
        return setupDockerLogs(docker, containerID, stdout, 0)
47✔
111
}
47✔
112

113
func MockDockerLogsExitCode(docker *client.Client, containerID string, exitCode int) error {
1✔
114
        return setupDockerLogs(docker, containerID, "", exitCode)
1✔
115
}
1✔
116

117
// MockDockerStartWithEnvCapture extends MockDockerStart to capture environment variables
118
// passed to container creation. This is useful for testing environment variable logic.
119
func MockDockerStartWithEnvCapture(docker *client.Client, imageID, containerID string, capturedEnv *[]string) {
4✔
120
        gock.New(docker.DaemonHost()).
4✔
121
                Get("/v" + docker.ClientVersion() + "/images/" + imageID + "/json").
4✔
122
                Reply(http.StatusOK).
4✔
123
                JSON(image.InspectResponse{})
4✔
124
        gock.New(docker.DaemonHost()).
4✔
125
                Post("/v" + docker.ClientVersion() + "/networks/create").
4✔
126
                Reply(http.StatusCreated).
4✔
127
                JSON(network.CreateResponse{})
4✔
128
        gock.New(docker.DaemonHost()).
4✔
129
                Post("/v" + docker.ClientVersion() + "/volumes/create").
4✔
130
                Persist().
4✔
131
                Reply(http.StatusCreated).
4✔
132
                JSON(volume.Volume{})
4✔
133
        gock.New(docker.DaemonHost()).
4✔
134
                Post("/v" + docker.ClientVersion() + "/containers/create").
4✔
135
                AddMatcher(func(req *http.Request, ereq *gock.Request) (bool, error) {
8✔
136
                        var config struct {
4✔
137
                                Env []string `json:"Env"`
4✔
138
                        }
4✔
139
                        if err := json.NewDecoder(req.Body).Decode(&config); err != nil {
4✔
NEW
140
                                return false, err
×
NEW
141
                        }
×
142
                        *capturedEnv = config.Env
4✔
143
                        return true, nil
4✔
144
                }).
145
                Reply(http.StatusOK).
146
                JSON(container.CreateResponse{ID: containerID})
147
        gock.New(docker.DaemonHost()).
4✔
148
                Post("/v" + docker.ClientVersion() + "/containers/" + containerID + "/start").
4✔
149
                Reply(http.StatusAccepted)
4✔
150
}
151

152
func ListUnmatchedRequests() []string {
240✔
153
        result := make([]string, len(gock.GetUnmatchedRequests()))
240✔
154
        for i, r := range gock.GetUnmatchedRequests() {
240✔
155
                result[i] = fmt.Sprintln(r.Method, r.URL.Path)
×
156
        }
×
157
        return result
240✔
158
}
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