github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/thirdparty/eventlog/context_test.go (about)

     1  package eventlog
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
     7  )
     8  
     9  func TestContextContainsMetadata(t *testing.T) {
    10  	t.Parallel()
    11  
    12  	m := Metadata{"foo": "bar"}
    13  	ctx := ContextWithLoggable(context.Background(), m)
    14  	got, err := MetadataFromContext(ctx)
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  
    19  	_, exists := got["foo"]
    20  	if !exists {
    21  		t.Fail()
    22  	}
    23  }
    24  
    25  func TestContextWithPreexistingMetadata(t *testing.T) {
    26  	t.Parallel()
    27  
    28  	ctx := ContextWithLoggable(context.Background(), Metadata{"hello": "world"})
    29  	ctx = ContextWithLoggable(ctx, Metadata{"goodbye": "earth"})
    30  
    31  	got, err := MetadataFromContext(ctx)
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  
    36  	_, exists := got["hello"]
    37  	if !exists {
    38  		t.Fatal("original key not present")
    39  	}
    40  	_, exists = got["goodbye"]
    41  	if !exists {
    42  		t.Fatal("new key not present")
    43  	}
    44  }