github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/translate_test.go (about)

     1  package alfred
     2  
     3  import (
     4  	"sync"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestTranslate(t *testing.T) {
    11  	context := &Context{
    12  		Lock: &sync.Mutex{},
    13  		Text: TextConfig{
    14  			Success:     "green",
    15  			SuccessIcon: "checkmark",
    16  			Failure:     "red",
    17  			FailureIcon: "x",
    18  		},
    19  	}
    20  	if translate("{{ .Text.Success }}", context) != "green" {
    21  		t.Fatalf(".Text.Success should be green")
    22  	}
    23  	if translate("{{ .Text.SuccessIcon }}", context) != "checkmark" {
    24  		t.Fatalf(".Text.SuccessIcon should be icon")
    25  	}
    26  	if translate("{{ .Text.Failure }}", context) != "red" {
    27  		t.Fatalf(".Text.Failure should be red")
    28  	}
    29  	assert.Equal(t, translate("{{ .Text.FailureIcon }}", context), "x", "Should be X")
    30  }