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.

54 lines
1.3 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 TestConfigYAML(t *testing.T) {
  8. cfg, err := config.ReadYAMLConfig([]byte(`---
  9. version: v4
  10. variants:
  11. foo: {}`))
  12. if assert.NoError(t, err) {
  13. assert.Equal(t, "v4", cfg.Version)
  14. assert.Contains(t, cfg.Variants, "foo")
  15. assert.IsType(t, config.VariantConfig{}, cfg.Variants["foo"])
  16. }
  17. }
  18. func TestConfigValidation(t *testing.T) {
  19. t.Run("variants", func(t *testing.T) {
  20. t.Run("ok", func(t *testing.T) {
  21. err := config.Validate(config.Config{
  22. VersionConfig: config.VersionConfig{Version: "v4"},
  23. Variants: map[string]config.VariantConfig{
  24. "build": config.VariantConfig{},
  25. "foo": config.VariantConfig{},
  26. },
  27. })
  28. assert.False(t, config.IsValidationError(err))
  29. })
  30. t.Run("bad", func(t *testing.T) {
  31. err := config.Validate(config.Config{
  32. VersionConfig: config.VersionConfig{Version: "v4"},
  33. Variants: map[string]config.VariantConfig{
  34. "build foo": config.VariantConfig{},
  35. "foo bar": config.VariantConfig{},
  36. },
  37. })
  38. if assert.True(t, config.IsValidationError(err)) {
  39. msg := config.HumanizeValidationError(err)
  40. assert.Equal(t, `variants: contains a bad variant name`, msg)
  41. }
  42. })
  43. })
  44. }