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

golang-migrate / migrate / 8701143885

16 Apr 2024 06:44AM UTC coverage: 56.335% (-2.9%) from 59.226%
8701143885

push

github

web-flow
Merge pull request #1072 from dhui/dktesting-cleanup

Delete db docker images after tests complete for a few large db docker images

0 of 20 new or added lines in 1 file covered. (0.0%)

4562 of 8098 relevant lines covered (56.33%)

61.74 hits per line

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

0.0
/dktesting/dktesting.go
1
package dktesting
2

3
import (
4
        "context"
5
        "fmt"
6
        "testing"
7
)
8

9
import (
10
        "github.com/dhui/dktest"
11
        "github.com/docker/docker/api/types"
12
        "github.com/docker/docker/client"
13
)
14

15
// ContainerSpec holds Docker testing setup specifications
16
type ContainerSpec struct {
17
        ImageName string
18
        Options   dktest.Options
19
}
20

21
// Cleanup cleanups the ContainerSpec after a test run by removing the ContainerSpec's image
NEW
22
func (s *ContainerSpec) Cleanup() (retErr error) {
×
NEW
23
        // copied from dktest.RunContext()
×
NEW
24
        dc, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
×
NEW
25
        if err != nil {
×
NEW
26
                return err
×
NEW
27
        }
×
NEW
28
        defer func() {
×
NEW
29
                if err := dc.Close(); err != nil && retErr == nil {
×
NEW
30
                        retErr = fmt.Errorf("error closing Docker client: %w", err)
×
NEW
31
                }
×
32
        }()
NEW
33
        cleanupTimeout := s.Options.CleanupTimeout
×
NEW
34
        if cleanupTimeout <= 0 {
×
NEW
35
                cleanupTimeout = dktest.DefaultCleanupTimeout
×
NEW
36
        }
×
NEW
37
        ctx, timeoutCancelFunc := context.WithTimeout(context.Background(), cleanupTimeout)
×
NEW
38
        defer timeoutCancelFunc()
×
NEW
39
        if _, err := dc.ImageRemove(ctx, s.ImageName, types.ImageRemoveOptions{Force: true, PruneChildren: true}); err != nil {
×
NEW
40
                return err
×
NEW
41
        }
×
NEW
42
        return nil
×
43
}
44

45
// ParallelTest runs Docker tests in parallel
46
func ParallelTest(t *testing.T, specs []ContainerSpec,
47
        testFunc func(*testing.T, dktest.ContainerInfo)) {
×
48

×
49
        for i, spec := range specs {
×
50
                spec := spec // capture range variable, see https://goo.gl/60w3p2
×
51

×
52
                // Only test against one version in short mode
×
53
                // TODO: order is random, maybe always pick first version instead?
×
54
                if i > 0 && testing.Short() {
×
55
                        t.Logf("Skipping %v in short mode", spec.ImageName)
×
56
                } else {
×
57
                        t.Run(spec.ImageName, func(t *testing.T) {
×
58
                                t.Parallel()
×
59
                                dktest.Run(t, spec.ImageName, spec.Options, testFunc)
×
60
                        })
×
61
                }
62
        }
63
}
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