github.com/kunnos/engine@v1.13.1/cli/compose/schema/schema_test.go (about)

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