...

Source file src/github.com/launchdarkly/go-sdk-common/v3/ldcontext/constructors_test.go

Documentation: github.com/launchdarkly/go-sdk-common/v3/ldcontext

     1  package ldcontext
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestNew(t *testing.T) {
    10  	c := New("my-key")
    11  	assert.Equal(t, NewBuilder("my-key").Build(), c)
    12  	// More detailed tests of the default state of the Context are in the tests for Builder. Here we have
    13  	// just verified that the constructor gives us the same result as Builder.
    14  }
    15  
    16  func TestNewErrors(t *testing.T) {
    17  	c := New("")
    18  
    19  	assert.Error(t, c.Err())
    20  }
    21  
    22  func TestNewWithKind(t *testing.T) {
    23  	c0 := NewWithKind("org", "my-key")
    24  	assert.Equal(t, NewBuilder("my-key").Kind("org").Build(), c0)
    25  	// More detailed tests of the default state of the Context are in the tests for Builder. Here we have
    26  	// just verified that the constructor gives us the same result as Builder.
    27  
    28  	c1 := NewWithKind("", "my-key")
    29  	assert.Equal(t, NewBuilder("my-key").Kind(DefaultKind).Build(), c1)
    30  }
    31  
    32  func TestNewWithKindErrors(t *testing.T) {
    33  	for _, p := range makeInvalidKindTestParams() {
    34  		t.Run(p.kind, func(t *testing.T) {
    35  			c := NewWithKind(Kind(p.kind), "my-key")
    36  			assert.Equal(t, p.err, c.Err())
    37  		})
    38  	}
    39  }
    40  
    41  func TestNewMulti(t *testing.T) {
    42  	sub1 := NewWithKind("kind1", "key1")
    43  	sub2 := NewWithKind("kind2", "key2")
    44  	sub3 := NewWithKind("kind3", "key3")
    45  	sub4 := NewWithKind("kind3", "key3")
    46  
    47  	assert.Equal(t, NewMultiBuilder().Add(sub1).Add(sub2).Build(), NewMulti(sub1, sub2))
    48  	assert.Equal(t, NewMultiBuilder().Add(sub1).Add(sub2).Add(sub3).Add(sub4).Build(),
    49  		NewMulti(sub1, NewMulti(sub2, sub3), sub4))
    50  }
    51  

View as plain text