Changeset View
Changeset View
Standalone View
Standalone View
config/variant_test.go
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | func TestVariantLoops(t *testing.T) { | ||||
assert.NotNil(t, err) | assert.NotNil(t, err) | ||||
_, errTwo := config.ExpandVariant(&cfgTwo, "bar") | _, errTwo := config.ExpandVariant(&cfgTwo, "bar") | ||||
assert.Nil(t, errTwo) | assert.Nil(t, errTwo) | ||||
} | } | ||||
func TestVariantConfigInstructions(t *testing.T) { | func TestVariantConfigInstructions(t *testing.T) { | ||||
t.Run("PhaseInstall", func(t *testing.T) { | t.Run("PhaseInstall", func(t *testing.T) { | ||||
t.Run("copies", func(t *testing.T) { | |||||
cfg := config.VariantConfig{Copies: "foo"} | |||||
assert.Empty(t, cfg.InstructionsForPhase(build.PhaseInstall)) | |||||
}) | |||||
t.Run("shared volume", func(t *testing.T) { | t.Run("shared volume", func(t *testing.T) { | ||||
cfg := config.VariantConfig{} | cfg := config.VariantConfig{} | ||||
cfg.Lives.In = "/srv/service" | cfg.Lives.In = "/srv/service" | ||||
cfg.SharedVolume.True = true | cfg.SharedVolume.True = true | ||||
assert.Equal(t, | assert.Equal(t, | ||||
[]build.Instruction{ | []build.Instruction{ | ||||
build.Volume{"/srv/service"}, | build.Volume{"/srv/service"}, | ||||
}, | }, | ||||
cfg.InstructionsForPhase(build.PhaseInstall), | cfg.InstructionsForPhase(build.PhaseInstall), | ||||
) | ) | ||||
}) | }) | ||||
t.Run("standard source copy", func(t *testing.T) { | t.Run("standard source copy", func(t *testing.T) { | ||||
cfg := config.VariantConfig{} | cfg := config.VariantConfig{} | ||||
cfg.Lives.UID = 123 | cfg.Lives.UID = 123 | ||||
cfg.Lives.GID = 223 | cfg.Lives.GID = 223 | ||||
assert.Equal(t, | assert.Equal(t, | ||||
[]build.Instruction{ | []build.Instruction{ | ||||
build.CopyAs{123, 223, build.Copy{[]string{"."}, "."}}, | build.CopyAs{UID: 123, GID: 223, Copy: build.Copy{[]string{"."}, "."}}, | ||||
}, | }, | ||||
cfg.InstructionsForPhase(build.PhaseInstall), | cfg.InstructionsForPhase(build.PhaseInstall), | ||||
) | ) | ||||
}) | }) | ||||
}) | |||||
t.Run("PhasePostInstall", func(t *testing.T) { | |||||
t.Run("for copies and artifacts", func(t *testing.T) { | t.Run("for copies and artifacts", func(t *testing.T) { | ||||
cfg := config.VariantConfig{ | cfg := config.VariantConfig{ | ||||
Copies: "foo", | Copies: "foo", | ||||
Artifacts: []config.ArtifactsConfig{ | Artifacts: []config.ArtifactsConfig{ | ||||
{From: "build", Source: "/foo/src", Destination: "/foo/dst"}, | {From: "build", Source: "/foo/src", Destination: "/foo/dst"}, | ||||
}, | }, | ||||
CommonConfig: config.CommonConfig{Lives: config.LivesConfig{In: "/srv/service"}}, | CommonConfig: config.CommonConfig{Lives: config.LivesConfig{In: "/srv/service"}}, | ||||
} | } | ||||
assert.Equal(t, | assert.Equal(t, | ||||
[]build.Instruction{ | []build.Instruction{ | ||||
build.CopyFrom{"foo", build.Copy{[]string{"/srv/service"}, "/srv/service"}}, | build.CopyFrom{"foo", build.Copy{[]string{"/srv/service"}, "/srv/service"}}, | ||||
build.CopyFrom{"foo", build.Copy{[]string{config.LocalLibPrefix}, config.LocalLibPrefix}}, | build.CopyFrom{"foo", build.Copy{[]string{config.LocalLibPrefix}, config.LocalLibPrefix}}, | ||||
build.CopyFrom{"build", build.Copy{[]string{"/foo/src"}, "/foo/dst"}}, | build.CopyFrom{"build", build.Copy{[]string{"/foo/src"}, "/foo/dst"}}, | ||||
}, | }, | ||||
cfg.InstructionsForPhase(build.PhasePostInstall), | cfg.InstructionsForPhase(build.PhaseInstall), | ||||
) | ) | ||||
}) | }) | ||||
t.Run("for just artifacts", func(t *testing.T) { | t.Run("for just artifacts", func(t *testing.T) { | ||||
cfg := config.VariantConfig{ | cfg := config.VariantConfig{ | ||||
Artifacts: []config.ArtifactsConfig{ | Artifacts: []config.ArtifactsConfig{ | ||||
{From: "build", Source: "/foo/src", Destination: "/foo/dst"}, | {From: "build", Source: "/foo/src", Destination: "/foo/dst"}, | ||||
}, | }, | ||||
CommonConfig: config.CommonConfig{Lives: config.LivesConfig{In: "/srv/service"}}, | CommonConfig: config.CommonConfig{ | ||||
Lives: config.LivesConfig{ | |||||
In: "/srv/service", | |||||
UserConfig: config.UserConfig{ | |||||
UID: 123, | |||||
GID: 223, | |||||
}, | |||||
}, | |||||
}, | |||||
} | } | ||||
assert.Equal(t, | assert.Equal(t, | ||||
[]build.Instruction{ | []build.Instruction{ | ||||
build.CopyFrom{"build", build.Copy{[]string{"/foo/src"}, "/foo/dst"}}, | build.CopyAs{ | ||||
UID: 123, | |||||
GID: 223, | |||||
Copy: build.Copy{[]string{"."}, "."}, | |||||
}, | |||||
build.CopyAs{ | |||||
UID: 123, | |||||
GID: 223, | |||||
CopyFrom: build.CopyFrom{"build", build.Copy{[]string{"/foo/src"}, "/foo/dst"}}, | |||||
}, | }, | ||||
cfg.InstructionsForPhase(build.PhasePostInstall), | }, | ||||
cfg.InstructionsForPhase(build.PhaseInstall), | |||||
) | ) | ||||
}) | }) | ||||
}) | |||||
t.Run("PhasePostInstall", func(t *testing.T) { | |||||
t.Run("with entrypoint", func(t *testing.T) { | t.Run("with entrypoint", func(t *testing.T) { | ||||
cfg := config.VariantConfig{ | cfg := config.VariantConfig{ | ||||
CommonConfig: config.CommonConfig{ | CommonConfig: config.CommonConfig{ | ||||
EntryPoint: []string{"/foo", "bar"}, | EntryPoint: []string{"/foo", "bar"}, | ||||
}, | }, | ||||
} | } | ||||
assert.Equal(t, | assert.Equal(t, | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 3.0 (CC-BY-SA) unless otherwise noted; code licensed under GNU General Public License (GPL) or other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL