summaryrefslogtreecommitdiff
path: root/config/builder_test.go
blob: 773ddd1e24d09ed25e0df4957cb9d8d3f58679c0 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package config_test

import (
	"testing"

	"github.com/stretchr/testify/assert"

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

func TestBuilderConfigYAML(t *testing.T) {
	cfg, err := config.ReadConfig([]byte(`---
    version: v2
    base: foo
    builder:
      command: [make, -f, Makefile, test]
      requirements: [Makefile]
    variants:
      test: {}
      build:
        builder:
          command: [make]
          requirements: []`))

	if assert.NoError(t, err) {
		variant, err := config.ExpandVariant(cfg, "test")

		if assert.NoError(t, err) {
			assert.Equal(t, []string{"make", "-f", "Makefile", "test"}, variant.Builder.Command)
			assert.Equal(t, []string{"Makefile"}, variant.Builder.Requirements)
		}

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

		if assert.NoError(t, err) {
			assert.Equal(t, []string{"make"}, variant.Builder.Command)
			assert.Equal(t, []string{}, variant.Builder.Requirements)
		}
	}
}

func TestBuilderConfigInstructions(t *testing.T) {
	cfg := config.BuilderConfig{Command: []string{"make", "-f", "Makefile"}}

	t.Run("PhasePreInstall", func(t *testing.T) {
		assert.Equal(t,
			[]build.Instruction{
				build.Run{
					"make",
					[]string{"-f", "Makefile"},
				},
			},
			cfg.InstructionsForPhase(build.PhasePreInstall),
		)
	})
}

func TestBuilderConfigInstructionsWithRequirements(t *testing.T) {
	cfg := config.BuilderConfig{
		Command:      []string{"make", "-f", "Makefile", "foo"},
		Requirements: []string{"Makefile", "foo", "bar/baz"},
	}

	t.Run("PhasePreInstall", func(t *testing.T) {
		assert.Equal(t,
			[]build.Instruction{
				build.Run{"mkdir -p", []string{"bar/"}},
				build.Copy{[]string{"Makefile", "foo"}, "./"},
				build.Copy{[]string{"bar/baz"}, "bar/"},
				build.Run{
					"make",
					[]string{"-f", "Makefile", "foo"},
				},
			},
			cfg.InstructionsForPhase(build.PhasePreInstall),
		)
	})
}