forked from TrueCloudLab/distribution
530afa5234
By adding WithVersion to the context package, we can simplify context setup in the application. This avoids some odd bugs where instantiation order can lead to missing instance.id or version from log messages. Signed-off-by: Stephen J Day <stephen.day@docker.com>
19 lines
366 B
Go
19 lines
366 B
Go
package context
|
|
|
|
import "testing"
|
|
|
|
func TestVersionContext(t *testing.T) {
|
|
ctx := Background()
|
|
|
|
if GetVersion(ctx) != "" {
|
|
t.Fatalf("context should not yet have a version")
|
|
}
|
|
|
|
expected := "2.1-whatever"
|
|
ctx = WithVersion(ctx, expected)
|
|
version := GetVersion(ctx)
|
|
|
|
if version != expected {
|
|
t.Fatalf("version was not set: %q != %q", version, expected)
|
|
}
|
|
}
|