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