github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/home_windows_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 //go:build windows 5 // +build windows 6 7 package libkb 8 9 import ( 10 "path/filepath" 11 "strings" 12 "testing" 13 ) 14 15 func doDirectoryTest(t *testing.T, d string, description string, suffix string) { 16 17 if len(d) == 0 { 18 t.Errorf("Bad %s dir", description) 19 } 20 parentDir, _ := filepath.Split(d) 21 if len(parentDir) == 0 || len(parentDir) == len(d) { 22 t.Errorf("Can't get parent of %s", d) 23 } 24 25 if !exists(parentDir) { 26 t.Errorf("%s does not exist", parentDir) 27 } 28 if len(suffix)+len(strings.TrimSuffix(d, suffix)) != len(d) { 29 t.Errorf("%s does not end with %s", d, suffix) 30 } 31 } 32 33 // There isn't much to test; the directory needn't exist yet 34 func TestWindows(t *testing.T) { 35 hf := NewHomeFinder("tester", nil, nil, nil, "windows", func() RunMode { return ProductionRunMode }, makeLogGetter(t), nil) 36 37 doDirectoryTest(t, hf.CacheDir(), "Cache", "") 38 doDirectoryTest(t, hf.DataDir(), "Data", "") 39 doDirectoryTest(t, hf.ConfigDir(), "Config", "") 40 41 hf = NewHomeFinder("tester", nil, nil, nil, "windows", func() RunMode { return StagingRunMode }, 42 makeLogGetter(t), nil) 43 44 doDirectoryTest(t, hf.CacheDir(), "Cache", "Staging") 45 doDirectoryTest(t, hf.DataDir(), "Data", "Staging") 46 doDirectoryTest(t, hf.ConfigDir(), "Config", "Staging") 47 48 hf = NewHomeFinder("tester", nil, nil, nil, "windows", func() RunMode { return DevelRunMode }, 49 makeLogGetter(t), nil) 50 51 doDirectoryTest(t, hf.CacheDir(), "Cache", "Devel") 52 doDirectoryTest(t, hf.DataDir(), "Data", "Devel") 53 doDirectoryTest(t, hf.ConfigDir(), "Config", "Devel") 54 55 whf := Win32{Base{"tester", nil, nil, nil, func() RunMode { return DevelRunMode }, makeLogGetter(t), nil}} 56 fromTemp := whf.deriveFromTemp() 57 if len(fromTemp) == 0 { 58 t.Errorf("%s does not exist", fromTemp) 59 } 60 61 if !exists(fromTemp) { 62 t.Errorf("%s does not exist", fromTemp) 63 } 64 65 }