github.hscsec.cn/u-root/u-root@v7.0.0+incompatible/cmds/core/printenv/printenv_test.go (about) 1 // Copyright 2016-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "bytes" 9 "os" 10 "strings" 11 "testing" 12 ) 13 14 func TestPrintenv(t *testing.T) { 15 // Setup some fake environment variables. 16 os.Clearenv() 17 os.Setenv("GIRAFFE", "akaros") 18 os.Setenv("GOPHER", "go") 19 os.Setenv("PENGUIN", "linux") 20 21 var buf bytes.Buffer 22 want := os.Environ() 23 printenv(&buf) 24 found := strings.Split(buf.String(), "\n") 25 26 for i, v := range want { 27 if v != found[i] { 28 t.Fatalf("want %s, got %s", v, found[i]) 29 } 30 } 31 }