github.com/Cloud-Foundations/Dominator@v0.3.4/imagebuilder/builder/variables_test.go (about)

     1  package builder
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  var (
     8  	testBuilder     = &Builder{}
     9  	testMappingFunc = func(name string) string {
    10  		return testStream.getenv()[name]
    11  	}
    12  	testStream = &imageStreamType{
    13  		name: "users/fred/generic/base/Debian-10/amd64",
    14  	}
    15  )
    16  
    17  func TestVariablesGetterAdder(t *testing.T) {
    18  	imageStream := &imageStreamType{}
    19  	vGetter := variablesGetter(imageStream.getenv()).copy()
    20  	key := "key"
    21  	value := "value"
    22  	vGetter.add(key, value)
    23  	result := vGetter.getenv()[key]
    24  	if result != value {
    25  		t.Errorf("expected: %s got: %s", value, result)
    26  	}
    27  }
    28  
    29  func TestSimpleExpressionExpansion(t *testing.T) {
    30  	result := expandExpression("${IMAGE_STREAM}", testMappingFunc)
    31  	if result != testStream.name {
    32  		t.Errorf("expected: %s got: %s", testStream.name, result)
    33  	}
    34  	result = expandExpression("${IMAGE_STREAM_DIRECTORY_NAME}", testMappingFunc)
    35  	expected := "users/fred/generic/base/Debian-10"
    36  	if result != expected {
    37  		t.Errorf("expected: %s got: %s", expected, result)
    38  	}
    39  	result = expandExpression("${IMAGE_STREAM_LEAF_NAME}", testMappingFunc)
    40  	expected = "amd64"
    41  	if result != expected {
    42  		t.Errorf("expected: %s got: %s", expected, result)
    43  	}
    44  }
    45  
    46  func TestSubExpressionExpansion(t *testing.T) {
    47  	result := expandExpression("${IMAGE_STREAM[/:]}", testMappingFunc)
    48  	if result != testStream.name {
    49  		t.Errorf("expected: %s got: %s", testStream.name, result)
    50  	}
    51  	result = expandExpression("${IMAGE_STREAM[/2:-1]}", testMappingFunc)
    52  	expected := "generic/base/Debian-10"
    53  	if result != expected {
    54  		t.Errorf("expected: %s got: %s", expected, result)
    55  	}
    56  }