summaryrefslogtreecommitdiff
path: root/config/common_test.go
blob: ba9333e75d2eb57ca3d8f9337af128f2eb8bdc2d (plain)
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
package config_test

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"gerrit.wikimedia.org/r/blubber/config"
)

func TestCommonConfigYAML(t *testing.T) {
	cfg, err := config.ReadConfig([]byte(`---
    version: v3
    base: fooimage
    entrypoint: ["/bin/foo"]
    variants:
      build: {}`))

	assert.Nil(t, err)

	assert.Equal(t, "fooimage", cfg.Base)
	assert.Equal(t, []string{"/bin/foo"}, cfg.EntryPoint)

	variant, err := config.ExpandVariant(cfg, "build")

	assert.Equal(t, "fooimage", variant.Base)
	assert.Equal(t, []string{"/bin/foo"}, variant.EntryPoint)
}

func TestCommonConfigValidation(t *testing.T) {
	t.Run("base", func(t *testing.T) {
		t.Run("ok", func(t *testing.T) {
			err := config.Validate(config.CommonConfig{
				Base: "foo",
			})

			assert.Nil(t, err)
		})

		t.Run("optional", func(t *testing.T) {
			err := config.Validate(config.CommonConfig{
				Base: "",
			})

			assert.False(t, config.IsValidationError(err))
		})

		t.Run("bad", func(t *testing.T) {
			err := config.Validate(config.CommonConfig{
				Base: "foo fighter",
			})

			if assert.True(t, config.IsValidationError(err)) {
				msg := config.HumanizeValidationError(err)

				assert.Equal(t, `base: "foo fighter" is not a valid base image reference`, msg)
			}
		})
	})
}