mirror of
https://github.com/distribution/distribution
synced 2024-11-06 19:35:52 +01:00
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>
20 lines
366 B
Go
20 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)
|
|
}
|
|
}
|