github.com/aitjcize/Overlord@v0.0.0-20240314041920-104a804cf5e8/overlord/sysutils_test.go (about) 1 // Copyright 2016 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package overlord 6 7 import ( 8 "os" 9 "path/filepath" 10 "testing" 11 ) 12 13 func TestGetMachineID(t *testing.T) { 14 mid, err := GetMachineID() 15 if err != nil { 16 t.Fatal(err) 17 } 18 19 if mid == "" { 20 t.Fatal("Machine ID is empty") 21 } 22 } 23 24 func TestGetProcessWorkingDirectory(t *testing.T) { 25 testPath := filepath.Join(os.TempDir(), "a/b/c") 26 27 if err := os.MkdirAll(testPath, 0777); err != nil { 28 t.Fatal(err) 29 } 30 31 if err := os.Chdir(testPath); err != nil { 32 t.Fatal(err) 33 } 34 35 wd, err := GetProcessWorkingDirectory(os.Getpid()) 36 if err != nil { 37 t.Fatal(err) 38 } 39 40 testPath, err = filepath.EvalSymlinks(testPath) 41 if err != nil { 42 t.Fatal(err) 43 } 44 45 if wd != testPath { 46 t.Fatalf("Working directory differs: (%s, %s)", testPath, wd) 47 } 48 49 os.RemoveAll(filepath.Join(os.TempDir(), "a")) 50 }