diff options
author | Dan Duvall <dduvall@wikimedia.org> | 2017-07-11 15:33:01 -0700 |
---|---|---|
committer | Dan Duvall <dduvall@wikimedia.org> | 2017-07-12 12:20:20 -0700 |
commit | 19b47a273717612e28374be9b63905985ce32ac9 (patch) | |
tree | f84ebb1083b92442793defbc98a3e39834ab9b24 /config | |
parent | 86071eec3deceb42b248cddbecce75cdb7f9e6f9 (diff) | |
download | blubber-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
Diffstat (limited to 'config')
-rw-r--r-- | config/apt_test.go | 62 | ||||
-rw-r--r-- | config/artifacts_test.go | 40 | ||||
-rw-r--r-- | config/common_test.go | 33 | ||||
-rw-r--r-- | config/npm.go | 6 | ||||
-rw-r--r-- | config/npm_test.go | 116 | ||||
-rw-r--r-- | config/runs_test.go | 1 |
6 files changed, 255 insertions, 3 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" |