-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocker_test.go
90 lines (79 loc) · 1.93 KB
/
docker_test.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"log"
"testing"
"github.com/spf13/afero"
"gopkg.in/src-d/go-billy.v4/memfs"
)
func TestNewDockerBuilder(t *testing.T) {
_, err := NewDockerBuilder(&BuildMatrix{}, []byte(""), "", "")
if err != nil {
t.Error("Should check for empty matrix or content")
}
}
func TestFolderFromGitURL(t *testing.T) {
const expected = "repository"
urls := []string{
"http://github.com/Owner/Repository",
"https://github.com/Owner/repository",
"[email protected]:Owner/repository.git",
}
for _, url := range urls {
f := folderFromGitURL(url)
if f != expected {
t.Errorf("Expected %s got %s.", expected, f)
}
}
}
func TestDockerBuilderAddFile(t *testing.T) {
err := afero.WriteFile(fs, "/test.txt", []byte("Test content"), 0644)
if err != nil {
t.Error(err)
}
log.Printf("FS: %+v\n", fs)
dockerBuilder := &DockerBuilder{
context: NewContext(),
}
err = dockerBuilder.addFile("", "/test.txt")
if err != nil {
t.Error("Should add file to context", err)
}
// TODO: Check that file is part of the context
}
func TestNewContext(t *testing.T) {
context := NewContext()
if context == nil {
t.Error("Should return a new context")
}
}
func TestContextAddFile(t *testing.T) {
context := NewContext()
if err := context.AddFile("test.txt", []byte("testing...")); err != nil {
t.Error(err, "Should add a file to context")
}
// TODO: Check that file is part of the context
}
func TestAddFilesystem(t *testing.T) {
context := NewContext()
fs := memfs.New()
fs.Create("test.txt")
err := context.AddFilesystem("", "", fs)
if err != nil {
t.Error(err, "Should add filesystem to Docker context")
}
// TODO: Check file is present
}
func TestClose(t *testing.T) {
context := NewContext()
err := context.Close()
if err != nil {
t.Error(err, "Should close Docker context")
}
}
func TestBytes(t *testing.T) {
context := NewContext()
b := context.Bytes()
if len(b) > 0 {
t.Error("Should return an empty context")
}
}