github.com/goonzoid/gcli@v0.2.3-0.20150926213610-155587606ea1/skeleton/template_test.go (about)

     1  package skeleton
     2  
     3  import "testing"
     4  
     5  func TestProcessPathTmpl(t *testing.T) {
     6  	tests := []struct {
     7  		Tmpl    string
     8  		data    interface{}
     9  		success bool
    10  		expect  string
    11  	}{
    12  		{
    13  			Tmpl:    "{{ .Name }}/README.md",
    14  			data:    Executable{Name: "todo"},
    15  			success: true,
    16  			expect:  "todo/README.md",
    17  		},
    18  
    19  		{
    20  			Tmpl:    "command/{{ .Name }}.go",
    21  			data:    Command{Name: "add"},
    22  			success: true,
    23  			expect:  "command/add.go",
    24  		},
    25  
    26  		{
    27  			Tmpl:    "{{ .NotExist }}.go",
    28  			data:    struct{}{},
    29  			success: false,
    30  		},
    31  	}
    32  
    33  	for i, tt := range tests {
    34  		output, err := processPathTmpl(tt.Tmpl, tt.data)
    35  		if tt.success && err != nil {
    36  			t.Fatalf("#%d expects error not to be occurred", i)
    37  		}
    38  
    39  		if output != tt.expect {
    40  			t.Errorf("#%d expects %s to eq %s", i, output, tt.expect)
    41  		}
    42  	}
    43  }