github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/internal/renderer/yatee/driver_test.go (about) 1 // +build experimental 2 3 package yatee 4 5 import ( 6 "testing" 7 8 "gotest.tools/assert" 9 is "gotest.tools/assert/cmp" 10 ) 11 12 const ( 13 compose = `version: "3.4" 14 services: 15 "@if $myapp.enable": 16 enabledservice: 17 image: alpine:$myapp.alpine_version 18 command: top $$foo 19 other: 20 image: nginx` 21 expectedCompose = `services: 22 enabledservice: 23 command: top $$foo 24 image: alpine:3.7 25 other: 26 image: nginx 27 version: "3.4" 28 ` 29 ) 30 31 var ( 32 settings = map[string]interface{}{ 33 "myapp": map[string]interface{}{ 34 "enable": true, 35 "alpine_version": "3.7", 36 }, 37 } 38 ) 39 40 func TestDriverErrors(t *testing.T) { 41 d := &Driver{} 42 _, err := d.Apply("service: $loop", nil) 43 assert.Check(t, err != nil) 44 assert.Check(t, is.ErrorContains(err, "variable 'loop' not set")) 45 } 46 47 func TestDriver(t *testing.T) { 48 d := &Driver{} 49 s, err := d.Apply(compose, settings) 50 assert.NilError(t, err) 51 t.Log(s) 52 assert.Check(t, is.Equal(s, expectedCompose)) 53 }