schema_test.go 907 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package schema
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. type dict map[string]interface{}
  7. func TestValidate(t *testing.T) {
  8. config := dict{
  9. "version": "3.0",
  10. "services": dict{
  11. "foo": dict{
  12. "image": "busybox",
  13. },
  14. },
  15. }
  16. assert.NoError(t, Validate(config, "3.0"))
  17. }
  18. func TestValidateUndefinedTopLevelOption(t *testing.T) {
  19. config := dict{
  20. "version": "3.0",
  21. "helicopters": dict{
  22. "foo": dict{
  23. "image": "busybox",
  24. },
  25. },
  26. }
  27. err := Validate(config, "3.0")
  28. assert.Error(t, err)
  29. assert.Contains(t, err.Error(), "Additional property helicopters is not allowed")
  30. }
  31. func TestValidateInvalidVersion(t *testing.T) {
  32. config := dict{
  33. "version": "2.1",
  34. "services": dict{
  35. "foo": dict{
  36. "image": "busybox",
  37. },
  38. },
  39. }
  40. err := Validate(config, "2.1")
  41. assert.Error(t, err)
  42. assert.Contains(t, err.Error(), "unsupported Compose file version: 2.1")
  43. }