forked from wjessop/build_ruby
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_ruby_test.go
124 lines (104 loc) · 3.84 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
package main
import (
"archive/tar"
"bytes"
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"path/filepath"
"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_output := 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
ADD 01_strict_hostname_checking.patch /
WORKDIR /tmp/ruby-2.1.34
RUN for i in `+"`/bin/ls /*.patch`"+`; do patch -p0 < $i; done
RUN CFLAGS='-march=x86-64 -O3 -fno-fast-math -g3 -ggdb -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -std=iso9899:1999 -fPIC' ./configure \
--prefix=/usr/local \
--enable-shared \
--disable-install-doc \
--enable-load-relative
# Seems to only affect some 1.9 series Rubies, but the combined make step:
#
# RUN make -j8 install DESTDIR=/tmp/fpm
#
# that ran the make then make install, was broken. Splitting it up into
# two separate commands works fine:
RUN make -j%d
RUN make install DESTDIR=/tmp/fpm
WORKDIR /
RUN fpm \
-s dir \
-t deb \
-n ruby \
-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 \
usr
`, 18)
assert.Equal(t, dockerFileFromTemplate("ubuntu:12.04", "2.1.34", "amd64", "37s~precise", []string{"01_strict_hostname_checking.patch"}, 18).String(), dockerfile_output)
}
func Test_rubyPackageFileName(t *testing.T) {
assert.Equal(t, "ruby-2.1.0_37s~raring_amd64.deb", rubyPackageFileName("2.1.0", "37s~raring", "amd64", "ubuntu:12.04"))
}
func Test_createTarFileFromDockerfile(t *testing.T) {
patch_files := []string{"Dockerfile", "data/patches/1.0.0/01_for_tests", "data/patches/1.0.0/02_for_tests"}
file_data := []string{"foo", "bar", "baz"}
tar_in_buffer := createTarFileFromDockerfile(bytes.NewBufferString("foo"), patch_files[1:3])
var tar_out *tar.Reader = tar.NewReader(tar_in_buffer)
for i, filename := range patch_files {
// Get the header so we can check the names of the files
tar_header, err := tar_out.Next()
if err != nil {
panic(err)
}
var out_bytes []byte
out_bytes, err = ioutil.ReadAll(tar_out)
if err != nil {
panic(err)
}
assert.Equal(t, tar_header.Name, filepath.Base(filename))
assert.Equal(t, string(out_bytes), file_data[i])
}
}
func Test_patchFilePathsFromRubyVersion(t *testing.T) {
patches := patchFilePathsFromRubyVersion("1.0.0")
expected_patches := []string{"data/patches/1.0.0/01_for_tests", "data/patches/1.0.0/02_for_tests"}
assert.Equal(t, patches, expected_patches)
}
func Test_copyPackageFromContainerToLocalFs(t *testing.T) {
t.Skip()
}
func Test_buildRuby(t *testing.T) {
t.Skip()
}