You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.5 KiB

  1. package config_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "gerrit.wikimedia.org/r/blubber/config"
  6. )
  7. func TestCommonConfigYAML(t *testing.T) {
  8. cfg, err := config.ReadYAMLConfig([]byte(`---
  9. version: v4
  10. base: fooimage
  11. entrypoint: ["/bin/foo"]
  12. variants:
  13. build: {}`))
  14. assert.Nil(t, err)
  15. assert.Equal(t, "fooimage", cfg.Base)
  16. assert.Equal(t, []string{"/bin/foo"}, cfg.EntryPoint)
  17. variant, err := config.ExpandVariant(cfg, "build")
  18. assert.Equal(t, "fooimage", variant.Base)
  19. assert.Equal(t, []string{"/bin/foo"}, variant.EntryPoint)
  20. }
  21. // Ensure that entrypoints inherit correctly
  22. //
  23. func TestEntryPointMerge(t *testing.T) {
  24. foo := config.CommonConfig{EntryPoint: []string{"/bin/foo"}}
  25. bar := config.CommonConfig{EntryPoint: []string{"/bin/bar"}}
  26. foo.Merge(bar)
  27. assert.Equal(t, []string{"/bin/bar"}, foo.EntryPoint)
  28. }
  29. func TestCommonConfigValidation(t *testing.T) {
  30. t.Run("base", func(t *testing.T) {
  31. t.Run("ok", func(t *testing.T) {
  32. err := config.Validate(config.CommonConfig{
  33. Base: "foo",
  34. })
  35. assert.Nil(t, err)
  36. })
  37. t.Run("optional", func(t *testing.T) {
  38. err := config.Validate(config.CommonConfig{
  39. Base: "",
  40. })
  41. assert.False(t, config.IsValidationError(err))
  42. })
  43. t.Run("bad", func(t *testing.T) {
  44. err := config.Validate(config.CommonConfig{
  45. Base: "foo fighter",
  46. })
  47. if assert.True(t, config.IsValidationError(err)) {
  48. msg := config.HumanizeValidationError(err)
  49. assert.Equal(t, `base: "foo fighter" is not a valid base image reference`, msg)
  50. }
  51. })
  52. })
  53. }