github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/internal/tests/integration/missing_key_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMissingKey_Default(t *testing.T) {
     8  	inOutTest(t, `{{ .name }}`, "<no value>", "--missing-key", "default")
     9  }
    10  
    11  func TestMissingKey_Zero(t *testing.T) {
    12  	inOutTest(t, `{{ .name }}`, "<no value>", "--missing-key", "zero")
    13  }
    14  
    15  func TestMissingKey_Fallback(t *testing.T) {
    16  	inOutTest(t, `{{ .name | default "Alex" }}`, "Alex", "--missing-key", "default")
    17  }
    18  
    19  func TestMissingKey_NotSpecified(t *testing.T) {
    20  	inOutContainsError(t, `{{ .name | default "Alex" }}`, `map has no entry for key \"name\"`)
    21  }
    22  
    23  func TestMissingKey_Error(t *testing.T) {
    24  	inOutContainsError(t, `{{ .name | default "Alex" }}`, `map has no entry for key \"name\"`, "--missing-key", "error")
    25  }