forked from wjessop/build_ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_ruby_test.go
149 lines (129 loc) · 4.19 KB
/
build_ruby_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"archive/tar"
"bytes"
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"runtime"
"testing"
)
/*
Unit tests. Skipped the tests that would have required mocking the Docker API
for now, may make them actually create package files.
*/
func Test_majorMinorVersionOnly(t *testing.T) {
assert.Equal(t, majorMinorVersionOnly("2.1.34"), "2.1")
assert.Equal(t, majorMinorVersionOnly("1.9.3-p635"), "1.9")
}
func Test_rubyDownloadUrl(t *testing.T) {
assert.Equal(t, rubyDownloadUrl("2.1.34"), "http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.34.tar.gz")
assert.Equal(t, rubyDownloadUrl("2.0.34-p451"), "http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.34-p451.tar.gz")
}
// Could do with pushing this out to go-bindata or similar
func Test_dockerFileFromTemplate(t *testing.T) {
dockerfile_putput := fmt.Sprintf(`FROM ubuntu:12.04
RUN apt-get update
RUN apt-get install -y ruby1.9.3 build-essential \
libc6-dev libffi-dev libgdbm-dev libncurses5-dev \
libreadline-dev libssl-dev libyaml-dev zlib1g-dev \
curl
RUN ["/usr/bin/gem", "install", "fpm", "--bindir=/usr/bin", "--no-rdoc", "--no-ri"]
RUN curl http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.34.tar.gz|tar oxzC /tmp
WORKDIR /tmp/ruby-2.1.34
RUN CFLAGS="-march=native -O3" ./configure \
--prefix=/opt/ruby2.1.34 \
--enable-shared \
--disable-install-doc \
--enable-load-relative
RUN make -j%d install DESTDIR=/tmp/fpm
WORKDIR /
RUN fpm \
-s dir \
-t deb \
-n ruby-2.1.34 \
-a amd64 \
-v 2.1.34 \
--iteration 37s~precise \
-d libc6-dev \
-d libffi-dev \
-d libgdbm-dev \
-d libncurses5-dev \
-d libreadline-dev \
-d libssl-dev \
-d libyaml-dev \
-d zlib1g-dev \
-C /tmp/fpm \
-p /ruby-2.1.34_37s~precise_amd64.deb \
opt
`, runtime.NumCPU())
assert.Equal(t, dockerFileFromTemplate("ubuntu:12.04", "2.1.34", "amd64", "37s~precise").String(), dockerfile_putput)
}
// Could do with pushing this out to go-bindata or similar
func Test_dockerFileFromTemplate_lucid(t *testing.T) {
dockerfile_putput := fmt.Sprintf(`FROM ubuntu:10.04
RUN echo "deb http://security.ubuntu.com/ubuntu lucid-security main" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y ruby1.9.1-full build-essential \
libc6-dev libffi-dev libgdbm-dev libncurses5-dev \
libreadline-dev libssl-dev libyaml-dev zlib1g-dev \
libopenssl-ruby1.9.1 ruby1.9.1-dev curl
RUN curl http://production.cf.rubygems.org/rubygems/rubygems-2.4.2.tgz |tar oxzC /tmp
RUN cd /tmp/rubygems-2.4.2 && ruby1.9.1 setup.rb
RUN gem1.9.1 install fpm --bindir=/usr/bin --no-rdoc --no-ri
RUN curl http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.34.tar.gz|tar oxzC /tmp
WORKDIR /tmp/ruby-2.1.34
RUN CFLAGS="-march=native -O3" ./configure \
--prefix=/opt/ruby2.1.34 \
--enable-shared \
--disable-install-doc \
--enable-load-relative
RUN make -j%d install DESTDIR=/tmp/fpm
WORKDIR /
RUN fpm \
-s dir \
-t deb \
-n ruby-2.1.34 \
-a amd64 \
-v 2.1.34 \
--iteration 37s~lucid \
-d libc6-dev \
-d libffi-dev \
-d libgdbm-dev \
-d libncurses5-dev \
-d libreadline-dev \
-d libssl-dev \
-d libyaml-dev \
-d zlib1g-dev \
-C /tmp/fpm \
-p /ruby-2.1.34_37s~lucid_amd64.deb \
opt
`, runtime.NumCPU())
assert.Equal(t, dockerFileFromTemplate("ubuntu:10.04", "2.1.34", "amd64", "37s~lucid").String(), dockerfile_putput)
}
func Test_rubyPackageFileName(t *testing.T) {
assert.Equal(t, "ruby-2.1.0_37s~raring_amd64.deb", rubyPackageFileName("2.1.0", "37s~raring", "amd64"))
}
func Test_createTarFileFromDockerfile(t *testing.T) {
tar_in_buffer := createTarFileFromDockerfile(bytes.NewBufferString("foo"))
var tar_out *tar.Reader = tar.NewReader(tar_in_buffer)
// Get the header so we can check the name of the only entry we care about
tar_header, err := tar_out.Next()
if err != nil {
panic(err)
}
// Get the data to make sure our foo made it through
var out_bytes []byte
out_bytes, err = ioutil.ReadAll(tar_out)
if err != nil {
panic(err)
}
assert.Equal(t, tar_header.Name, "Dockerfile")
assert.Equal(t, string(out_bytes), "foo")
}
func Test_copyPackageFromContainerToLocalFs(t *testing.T) {
t.Skip()
}
func Test_buildRuby(t *testing.T) {
t.Skip()
}