Skip to content

Commit 9bca068

Browse files
pbarkerarekkas
authored andcommitted
Adds labels to docker config (#128)
1 parent 7b75083 commit 9bca068

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

dockertest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ type RunOptions struct {
161161
ExposedPorts []string
162162
ExtraHosts []string
163163
WorkingDir string
164+
Labels map[string]string
164165
Auth dc.AuthConfiguration
165166
PortBindings map[dc.Port][]dc.PortBinding
166167
}
@@ -250,6 +251,7 @@ func (d *Pool) RunWithOptions(opts *RunOptions) (*Resource, error) {
250251
Mounts: mounts,
251252
ExposedPorts: exp,
252253
WorkingDir: wd,
254+
Labels: opts.Labels,
253255
},
254256
HostConfig: &dc.HostConfig{
255257
PublishAllPorts: true,

dockertest_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"os"
1010
"testing"
1111

12-
dc "github.com/ory/dockertest/docker"
1312
_ "github.com/lib/pq"
13+
dc "github.com/ory/dockertest/docker"
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
1616
)
@@ -88,6 +88,23 @@ func TestContainerWithName(t *testing.T) {
8888
require.Nil(t, pool.Purge(resource))
8989
}
9090

91+
func TestContainerWithLabels(t *testing.T) {
92+
labels := map[string]string{
93+
"my": "label",
94+
}
95+
resource, err := pool.RunWithOptions(
96+
&RunOptions{
97+
Name: "db",
98+
Repository: "postgres",
99+
Tag: "9.5",
100+
Labels: labels,
101+
})
102+
require.Nil(t, err)
103+
assert.EqualValues(t, labels, resource.Container.Config.Labels, "labels don't match")
104+
105+
require.Nil(t, pool.Purge(resource))
106+
}
107+
91108
func TestContainerWithPortBinding(t *testing.T) {
92109
resource, err := pool.RunWithOptions(
93110
&RunOptions{

0 commit comments

Comments
 (0)