github.com/xiaobinqt/libcompose@v1.1.0/lookup/composable_test.go (about)

     1  package lookup
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/xiaobinqt/libcompose/config"
     7  )
     8  
     9  type simpleEnvLookup struct {
    10  	value []string
    11  }
    12  
    13  func (l *simpleEnvLookup) Lookup(key string, config *config.ServiceConfig) []string {
    14  	return l.value
    15  }
    16  
    17  func TestComposableLookupWithoutAnyLookup(t *testing.T) {
    18  	envLookup := &ComposableEnvLookup{}
    19  	actuals := envLookup.Lookup("any", nil)
    20  	if len(actuals) != 0 {
    21  		t.Fatalf("expected an empty slice, got %v", actuals)
    22  	}
    23  }
    24  
    25  func TestComposableLookupReturnsTheLastValue(t *testing.T) {
    26  	envLookup1 := &simpleEnvLookup{
    27  		value: []string{"value=1"},
    28  	}
    29  	envLookup2 := &simpleEnvLookup{
    30  		value: []string{"value=2"},
    31  	}
    32  	envLookup := &ComposableEnvLookup{
    33  		[]config.EnvironmentLookup{
    34  			envLookup1,
    35  			envLookup2,
    36  		},
    37  	}
    38  	validateLookup(t, "value=2", envLookup.Lookup("value", nil))
    39  
    40  	envLookup = &ComposableEnvLookup{
    41  		[]config.EnvironmentLookup{
    42  			envLookup2,
    43  			envLookup1,
    44  		},
    45  	}
    46  	validateLookup(t, "value=1", envLookup.Lookup("value", nil))
    47  }