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.

79 lines
1.9 KiB

  1. package config_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "gerrit.wikimedia.org/r/blubber/build"
  6. "gerrit.wikimedia.org/r/blubber/config"
  7. )
  8. func TestBuilderConfigYAML(t *testing.T) {
  9. cfg, err := config.ReadYAMLConfig([]byte(`---
  10. version: v4
  11. base: foo
  12. builder:
  13. command: [make, -f, Makefile, test]
  14. requirements: [Makefile]
  15. variants:
  16. test: {}
  17. build:
  18. builder:
  19. command: [make]
  20. requirements: []`))
  21. if assert.NoError(t, err) {
  22. variant, err := config.ExpandVariant(cfg, "test")
  23. if assert.NoError(t, err) {
  24. assert.Equal(t, []string{"make", "-f", "Makefile", "test"}, variant.Builder.Command)
  25. assert.Equal(t, []string{"Makefile"}, variant.Builder.Requirements)
  26. }
  27. variant, err = config.ExpandVariant(cfg, "build")
  28. if assert.NoError(t, err) {
  29. assert.Equal(t, []string{"make"}, variant.Builder.Command)
  30. assert.Equal(t, []string{}, variant.Builder.Requirements)
  31. }
  32. }
  33. }
  34. func TestBuilderConfigInstructions(t *testing.T) {
  35. cfg := config.BuilderConfig{Command: []string{"make", "-f", "Makefile"}}
  36. t.Run("PhasePreInstall", func(t *testing.T) {
  37. assert.Equal(t,
  38. []build.Instruction{
  39. build.Run{
  40. "make",
  41. []string{"-f", "Makefile"},
  42. },
  43. },
  44. cfg.InstructionsForPhase(build.PhasePreInstall),
  45. )
  46. })
  47. }
  48. func TestBuilderConfigInstructionsWithRequirements(t *testing.T) {
  49. cfg := config.BuilderConfig{
  50. Command: []string{"make", "-f", "Makefile", "foo"},
  51. Requirements: []string{"Makefile", "foo", "bar/baz"},
  52. }
  53. t.Run("PhasePreInstall", func(t *testing.T) {
  54. assert.Equal(t,
  55. []build.Instruction{
  56. build.Run{"mkdir -p", []string{"bar/"}},
  57. build.Copy{[]string{"Makefile", "foo"}, "./"},
  58. build.Copy{[]string{"bar/baz"}, "bar/"},
  59. build.Run{
  60. "make",
  61. []string{"-f", "Makefile", "foo"},
  62. },
  63. },
  64. cfg.InstructionsForPhase(build.PhasePreInstall),
  65. )
  66. })
  67. }