summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Duvall <dduvall@wikimedia.org>2017-07-11 15:33:01 -0700
committerDan Duvall <dduvall@wikimedia.org>2017-07-12 12:20:20 -0700
commit19b47a273717612e28374be9b63905985ce32ac9 (patch)
treef84ebb1083b92442793defbc98a3e39834ab9b24
parent86071eec3deceb42b248cddbecce75cdb7f9e6f9 (diff)
downloadblubber-19b47a273717612e28374be9b63905985ce32ac9.tar.gz
Broaden base test coverage
Summary: Implemented tests for config types and removed deprecated docker compiler tests. Fixes T168001 Test Plan: Run `arc unit --everything` or `go test ./...`. Reviewers: thcipriani, mmodell, #release-engineering-team Reviewed By: thcipriani, #release-engineering-team Tags: #release-engineering-team Maniphest Tasks: T168001 Differential Revision: https://phabricator.wikimedia.org/D711
-rw-r--r--config/apt_test.go62
-rw-r--r--config/artifacts_test.go40
-rw-r--r--config/common_test.go33
-rw-r--r--config/npm.go6
-rw-r--r--config/npm_test.go116
-rw-r--r--config/runs_test.go1
-rw-r--r--docker/compiler_test.go20
7 files changed, 255 insertions, 23 deletions
diff --git a/config/apt_test.go b/config/apt_test.go
new file mode 100644
index 0000000..3801231
--- /dev/null
+++ b/config/apt_test.go
@@ -0,0 +1,62 @@
+package config_test
+
+import (
+ "testing"
+
+ "gopkg.in/stretchr/testify.v1/assert"
+
+ "phabricator.wikimedia.org/source/blubber.git/build"
+ "phabricator.wikimedia.org/source/blubber.git/config"
+)
+
+func TestAptConfig(t *testing.T) {
+ cfg, err := config.ReadConfig([]byte(`---
+ 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.Run, []string{
+ "apt-get update && apt-get install -y ",
+ "libfoo libbar",
+ " && rm -rf /var/lib/apt/lists/*",
+ }},
+ },
+ 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))
+ })
+}
diff --git a/config/artifacts_test.go b/config/artifacts_test.go
new file mode 100644
index 0000000..09f2ae4
--- /dev/null
+++ b/config/artifacts_test.go
@@ -0,0 +1,40 @@
+package config_test
+
+import (
+ "testing"
+
+ "gopkg.in/stretchr/testify.v1/assert"
+
+ "phabricator.wikimedia.org/source/blubber.git/config"
+)
+
+func TestArtifactsConfig(t *testing.T) {
+ cfg, err := config.ReadConfig([]byte(`---
+ variants:
+ build: {}
+ production:
+ artifacts:
+ - from: build
+ source: /foo/src
+ destination: /foo/dst
+ - from: build
+ source: /bar/src
+ destination: /bar/dst`))
+
+ assert.Nil(t, err)
+
+ variant, err := config.ExpandVariant(cfg, "production")
+
+ assert.Nil(t, err)
+
+ assert.Len(t, variant.Artifacts, 2)
+
+ assert.Contains(t,
+ variant.Artifacts,
+ config.ArtifactsConfig{From: "build", Source: "/foo/src", Destination: "/foo/dst"},
+ )
+ assert.Contains(t,
+ variant.Artifacts,
+ config.ArtifactsConfig{From: "build", Source: "/bar/src", Destination: "/bar/dst"},
+ )
+}
diff --git a/config/common_test.go b/config/common_test.go
new file mode 100644
index 0000000..1cce81d
--- /dev/null
+++ b/config/common_test.go
@@ -0,0 +1,33 @@
+package config_test
+
+import (
+ "testing"
+
+ "gopkg.in/stretchr/testify.v1/assert"
+
+ "phabricator.wikimedia.org/source/blubber.git/config"
+)
+
+func TestCommonConfig(t *testing.T) {
+ cfg, err := config.ReadConfig([]byte(`---
+ base: fooimage
+ apt: {}
+ npm: {}
+ runs: {}
+ sharedvolume: true
+ entrypoint: ["/bin/foo"]
+ variants:
+ build: {}`))
+
+ assert.Nil(t, err)
+
+ assert.Equal(t, "fooimage", cfg.Base)
+ assert.Equal(t, true, cfg.SharedVolume.True)
+ assert.Equal(t, []string{"/bin/foo"}, cfg.EntryPoint)
+
+ variant, err := config.ExpandVariant(cfg, "build")
+
+ assert.Equal(t, "fooimage", variant.Base)
+ assert.Equal(t, true, variant.SharedVolume.True)
+ assert.Equal(t, []string{"/bin/foo"}, variant.EntryPoint)
+}
diff --git a/config/npm.go b/config/npm.go
index f6ed323..f263d24 100644
--- a/config/npm.go
+++ b/config/npm.go
@@ -31,13 +31,13 @@ func (npm NpmConfig) InstructionsForPhase(phase build.Phase) []build.Instruction
}
return []build.Instruction{
- {build.Run, []string{"mkdir -p ", tempNpmInstallDir}},
+ {build.Run, []string{"mkdir -p " + tempNpmInstallDir}},
{build.Copy, []string{"package.json", tempNpmInstallDir}},
- {build.Run, []string{"cd ", tempNpmInstallDir, " && ", npmCmd}},
+ {build.Run, []string{"cd " + tempNpmInstallDir + " && " + npmCmd}},
}
case build.PhasePostInstall:
return []build.Instruction{
- {build.Run, []string{"mv ", path.Join(tempNpmInstallDir, "node_modules"), " ./"}},
+ {build.Run, []string{"mv " + path.Join(tempNpmInstallDir, "node_modules") + " ./"}},
}
}
}
diff --git a/config/npm_test.go b/config/npm_test.go
new file mode 100644
index 0000000..69799a9
--- /dev/null
+++ b/config/npm_test.go
@@ -0,0 +1,116 @@
+package config_test
+
+import (
+ "testing"
+
+ "gopkg.in/stretchr/testify.v1/assert"
+
+ "phabricator.wikimedia.org/source/blubber.git/build"
+ "phabricator.wikimedia.org/source/blubber.git/config"
+)
+
+func TestNpmConfig(t *testing.T) {
+ cfg, err := config.ReadConfig([]byte(`---
+ npm:
+ install: true
+ env: foo
+ variants:
+ build:
+ npm:
+ install: false
+ env: bar`))
+
+ assert.Nil(t, err)
+
+ assert.Equal(t, true, cfg.Npm.Install.True)
+ assert.Equal(t, "foo", cfg.Npm.Env)
+
+ variant, err := config.ExpandVariant(cfg, "build")
+
+ assert.Equal(t, false, variant.Npm.Install.True)
+ assert.Equal(t, "bar", variant.Npm.Env)
+}
+
+func TestNpmConfigInstructionsNoInstall(t *testing.T) {
+ cfg := config.NpmConfig{Install: config.Flag{True: false}}
+
+ t.Run("PhasePrivileged", func(t *testing.T) {
+ assert.Empty(t, 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 TestNpmConfigInstructionsNonProduction(t *testing.T) {
+ cfg := config.NpmConfig{Install: config.Flag{True: true}, Env: "foo"}
+
+ t.Run("PhasePrivileged", func(t *testing.T) {
+ assert.Empty(t, 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.Equal(t,
+ []build.Instruction{
+ {build.Run, []string{"mkdir -p /tmp/node-deps/"}},
+ {build.Copy, []string{"package.json", "/tmp/node-deps/"}},
+ {build.Run, []string{"cd /tmp/node-deps/ && npm install"}},
+ },
+ cfg.InstructionsForPhase(build.PhasePreInstall),
+ )
+ })
+
+ t.Run("PhasePostInstall", func(t *testing.T) {
+ assert.Equal(t,
+ []build.Instruction{
+ {build.Run, []string{"mv /tmp/node-deps/node_modules ./"}},
+ },
+ cfg.InstructionsForPhase(build.PhasePostInstall),
+ )
+ })
+}
+
+func TestNpmConfigInstructionsProduction(t *testing.T) {
+ cfg := config.NpmConfig{Install: config.Flag{True: true}, Env: "production"}
+
+ t.Run("PhasePrivileged", func(t *testing.T) {
+ assert.Empty(t, 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.Equal(t,
+ []build.Instruction{
+ {build.Run, []string{"mkdir -p /tmp/node-deps/"}},
+ {build.Copy, []string{"package.json", "/tmp/node-deps/"}},
+ {build.Run, []string{"cd /tmp/node-deps/ && npm install --production && npm dedupe"}},
+ },
+ cfg.InstructionsForPhase(build.PhasePreInstall),
+ )
+ })
+
+ t.Run("PhasePostInstall", func(t *testing.T) {
+ assert.Equal(t,
+ []build.Instruction{
+ {build.Run, []string{"mv /tmp/node-deps/node_modules ./"}},
+ },
+ cfg.InstructionsForPhase(build.PhasePostInstall),
+ )
+ })
+}
diff --git a/config/runs_test.go b/config/runs_test.go
index 119ef3f..f8c626e 100644
--- a/config/runs_test.go
+++ b/config/runs_test.go
@@ -2,6 +2,7 @@ package config_test
import (
"testing"
+
"gopkg.in/stretchr/testify.v1/assert"
"phabricator.wikimedia.org/source/blubber.git/config"
diff --git a/docker/compiler_test.go b/docker/compiler_test.go
index 8981683..d6a1a53 100644
--- a/docker/compiler_test.go
+++ b/docker/compiler_test.go
@@ -1,12 +1,10 @@
package docker_test
import (
- "bytes"
"testing"
"gopkg.in/stretchr/testify.v1/assert"
- "phabricator.wikimedia.org/source/blubber.git/build"
"phabricator.wikimedia.org/source/blubber.git/config"
"phabricator.wikimedia.org/source/blubber.git/docker"
)
@@ -42,21 +40,3 @@ func TestMultiStageIncludesStageNames(t *testing.T) {
assert.Contains(t, dockerfile, "FROM foo/bar AS build\n")
assert.Contains(t, dockerfile, "FROM foo/bar AS production\n")
}
-
-func TestCompileInstructionCopy(t *testing.T) {
- buffer := new(bytes.Buffer)
- instruction := build.Instruction{build.Copy, []string{"foo", "bar"}}
-
- docker.CompileInstruction(buffer, instruction)
-
- assert.Equal(t, "COPY [\"foo\", \"bar\"]\n", buffer.String())
-}
-
-func TestCompileInstructionEnv(t *testing.T) {
- buffer := new(bytes.Buffer)
- instruction := build.Instruction{build.Env, []string{"foo=bar", "baz=qux"}}
-
- docker.CompileInstruction(buffer, instruction)
-
- assert.Equal(t, "ENV foo=bar \\\n baz=qux\n", buffer.String())
-}