github.com/simonferquel/app@v0.6.1-0.20181012141724-68b7cccf26ac/internal/renderer/mustache/driver_test.go (about)

     1  // +build experimental
     2  
     3  package mustache
     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  {{#myapp.enable}}
    16    enabledservice:
    17      image: alpine:{{myapp.alpine_version}}
    18      command: top
    19  {{/myapp.enable}}
    20    other:
    21      image: nginx`
    22  	expectedCompose = `version: "3.4"
    23  services:
    24    enabledservice:
    25      image: alpine:3.7
    26      command: top
    27    other:
    28      image: nginx`
    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  	testCases := []struct {
    42  		name          string
    43  		template      string
    44  		settings      map[string]interface{}
    45  		expectedError string
    46  	}{
    47  		{
    48  			name:          "invalid template",
    49  			template:      "{{}}",
    50  			expectedError: "empty tag",
    51  		},
    52  	}
    53  	d := &Driver{}
    54  	for _, tc := range testCases {
    55  		_, err := d.Apply(tc.template, tc.settings)
    56  		assert.Check(t, err != nil)
    57  		assert.Check(t, is.ErrorContains(err, tc.expectedError))
    58  	}
    59  }
    60  
    61  func TestDriver(t *testing.T) {
    62  	d := &Driver{}
    63  	s, err := d.Apply(compose, settings)
    64  	assert.NilError(t, err)
    65  	assert.Check(t, is.Equal(s, expectedCompose))
    66  }