mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com> # TYPES # feat # fix # docs # style (formatting, missing semi colons, etc; no code change): # refactor # test (adding missing tests, refactoring tests; no production code change) # chore (updating grunt tasks etc; no production code change) Signed-off-by: Brian Tiger Chow <brian.holderchow@gmail.com>
45 lines
850 B
Go
45 lines
850 B
Go
package eventlog
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
|
)
|
|
|
|
func TestContextContainsMetadata(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
m := Metadata{"foo": "bar"}
|
|
ctx := ContextWithMetadata(context.Background(), m)
|
|
got, err := MetadataFromContext(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, exists := got["foo"]
|
|
if !exists {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestContextWithPreexistingMetadata(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := ContextWithMetadata(context.Background(), Metadata{"hello": "world"})
|
|
ctx = ContextWithMetadata(ctx, Metadata{"goodbye": "earth"})
|
|
|
|
got, err := MetadataFromContext(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, exists := got["hello"]
|
|
if !exists {
|
|
t.Fatal("original key not present")
|
|
}
|
|
_, exists = got["goodbye"]
|
|
if !exists {
|
|
t.Fatal("new key not present")
|
|
}
|
|
}
|