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
|
package config_test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"phabricator.wikimedia.org/source/blubber/build"
"phabricator.wikimedia.org/source/blubber/config"
)
func TestAptConfigYAML(t *testing.T) {
cfg, err := config.ReadConfig([]byte(`---
version: v2
apt:
packages:
- libfoo
- libbar
variants:
build:
apt:
packages:
- libfoo-dev`))
assert.Nil(t, err)
assert.Equal(t, []string{"libfoo", "libbar"}, cfg.Apt.Packages)
variant, err := config.ExpandVariant(cfg, "build")
assert.Nil(t, err)
assert.Equal(t, []string{"libfoo", "libbar", "libfoo-dev"}, variant.Apt.Packages)
}
func TestAptConfigInstructions(t *testing.T) {
cfg := config.AptConfig{Packages: []string{"libfoo", "libbar"}}
t.Run("PhasePrivileged", func(t *testing.T) {
assert.Equal(t,
[]build.Instruction{
build.Env{map[string]string{
"DEBIAN_FRONTEND": "noninteractive",
}},
build.RunAll{[]build.Run{
{"apt-get update", []string{}},
{"apt-get install -y", []string{"libfoo", "libbar"}},
{"rm -rf /var/lib/apt/lists/*", []string{}},
}},
},
cfg.InstructionsForPhase(build.PhasePrivileged),
)
})
t.Run("PhasePrivilegeDropped", func(t *testing.T) {
assert.Empty(t, cfg.InstructionsForPhase(build.PhasePrivilegeDropped))
})
t.Run("PhasePreInstall", func(t *testing.T) {
assert.Empty(t, cfg.InstructionsForPhase(build.PhasePreInstall))
})
t.Run("PhasePostInstall", func(t *testing.T) {
assert.Empty(t, cfg.InstructionsForPhase(build.PhasePostInstall))
})
}
func TestAptConfigValidation(t *testing.T) {
t.Run("packages", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
err := config.Validate(config.AptConfig{
Packages: []string{
"f1",
"foo-fighter",
"bar+b.az",
"bar+b.az=0:0.1~foo1-1",
"bar+b.az/stable",
"bar+b.az/jessie-wikimedia",
},
})
assert.False(t, config.IsValidationError(err))
})
t.Run("bad", func(t *testing.T) {
err := config.Validate(config.AptConfig{
Packages: []string{
"f1",
"foo fighter",
"bar_baz",
"bar=0.1*bad version",
"bar/0bad_release",
},
})
if assert.True(t, config.IsValidationError(err)) {
msg := config.HumanizeValidationError(err)
assert.Equal(t, strings.Join([]string{
`packages[1]: "foo fighter" is not a valid Debian package name`,
`packages[2]: "bar_baz" is not a valid Debian package name`,
`packages[3]: "bar=0.1*bad version" is not a valid Debian package name`,
`packages[4]: "bar/0bad_release" is not a valid Debian package name`,
}, "\n"), msg)
}
})
})
}
|