forked from TrueCloudLab/distribution
d0f5aa670b
Our context package predates the establishment of current best practices regarding context usage and it shows. It encourages bad practices such as using contexts to propagate non-request-scoped values like the application version and using string-typed keys for context values. Move the package internal to remove it from the API surface of distribution/v3@v3.0.0 so we are free to iterate on it without being constrained by compatibility. Signed-off-by: Cory Snider <csnider@mirantis.com>
19 lines
367 B
Go
19 lines
367 B
Go
package dcontext
|
|
|
|
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)
|
|
}
|
|
}
|