-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_test.go
More file actions
51 lines (43 loc) · 1.22 KB
/
Copy pathdocker_test.go
File metadata and controls
51 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cacertsonthefly_test
import (
"context"
"io"
"regexp"
"strings"
"testing"
"time"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
var regex = regexp.MustCompile(`(-----BEGIN CERTIFICATE-----(\n|\r|\r\n)([0-9a-zA-Z\+\/=]{64}(\n|\r|\r\n))*([0-9a-zA-Z\+\/=]{1,63}(\n|\r|\r\n))?-----END CERTIFICATE-----)`)
func TestBasic(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
Started: true,
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: ".",
KeepImage: false,
},
WaitingFor: wait.NewFileStrategy("/tmp/certs/ca-certificates.crt"),
},
})
if err != nil {
t.Error(err)
}
defer testcontainers.CleanupContainer(t, container)
r, err := container.CopyFileFromContainer(ctx, "/tmp/certs/ca-certificates.crt")
if err != nil {
t.Error(err)
}
buffer := &strings.Builder{}
_, err = io.Copy(buffer, r)
if err != nil {
t.Error(err)
}
s := buffer.String()
if !regex.MatchString(s) {
t.Error("ca-certificates.crt not in PEM format")
}
}