From 07aa4d96ea1553ea4c15c243caed88738168fd0e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 15 Feb 2025 15:37:34 +0100 Subject: [PATCH] container: TestReplaceAndAppendEnvVars: assert with gotest.tools Assert the actual results match the expected one, which should make the test more complete, and reduces some noise by removing a `t.Log`. Signed-off-by: Sebastiaan van Stijn --- container/env_test.go | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/container/env_test.go b/container/env_test.go index 432d43a4b2..defbacfff6 100644 --- a/container/env_test.go +++ b/container/env_test.go @@ -8,24 +8,14 @@ import ( ) func TestReplaceAndAppendEnvVars(t *testing.T) { - var ( - d = []string{"HOME=/", "FOO=foo_default"} - // remove FOO from env - // remove BAR from env (nop) - o = []string{"HOME=/root", "TERM=xterm", "FOO", "BAR"} - ) + origEnv := []string{"HOME=/", "FOO=foo_default"} + // remove FOO from env + // remove BAR from env (nop) + overrides := []string{"HOME=/root", "TERM=xterm", "FOO", "BAR"} - env := ReplaceOrAppendEnvValues(d, o) - t.Logf("default=%v, override=%v, result=%v", d, o, env) - if len(env) != 2 { - t.Fatalf("expected len of 2 got %d", len(env)) - } - if env[0] != "HOME=/root" { - t.Fatalf("expected HOME=/root got '%s'", env[0]) - } - if env[1] != "TERM=xterm" { - t.Fatalf("expected TERM=xterm got '%s'", env[1]) - } + env := ReplaceOrAppendEnvValues(origEnv, overrides) + expected := []string{"HOME=/root", "TERM=xterm"} + assert.DeepEqual(t, env, expected) } func BenchmarkReplaceOrAppendEnvValues(b *testing.B) {