Add WithVersion to context and other cleanup
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>
This commit is contained in:
parent
360c24d975
commit
530afa5234
6 changed files with 62 additions and 11 deletions
19
context/version_test.go
Normal file
19
context/version_test.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue