1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/context/context_test.go
Doug Davis f790496d8b Move context stuff to its own package
Signed-off-by: Doug Davis <dug@us.ibm.com>
2015-09-09 14:23:25 -07:00

35 lines
871 B
Go

package context
import (
"testing"
"github.com/docker/docker/pkg/version"
)
func TestContext(t *testing.T) {
ctx := Background()
// First make sure getting non-existent values doesn't break
if id := ctx.RequestID(); id != "" {
t.Fatalf("RequestID() should have been '', was: %q", id)
}
if ver := ctx.Version(); ver != "" {
t.Fatalf("Version() should have been '', was: %q", ver)
}
// Test basic set/get
ctx = WithValue(ctx, RequestID, "123")
if ctx.RequestID() != "123" {
t.Fatalf("RequestID() should have been '123'")
}
// Now make sure after a 2nd set we can still get both
ctx = WithValue(ctx, APIVersion, version.Version("x.y"))
if id := ctx.RequestID(); id != "123" {
t.Fatalf("RequestID() should have been '123', was %q", id)
}
if ver := ctx.Version(); ver != "x.y" {
t.Fatalf("Version() should have been 'x.y', was %q", ver)
}
}