@@ -17,9 +17,9 @@ func TestBtoi(t *testing.T) {
17
17
18
18
func TestGoogleChromeProfilesColumns (t * testing.T ) {
19
19
columns := GoogleChromeProfilesColumns ()
20
- assert .Len (t , columns , 4 )
20
+ assert .Len (t , columns , 5 )
21
21
22
- expectedColumnNames := []string {"username" , "email" , "name" , "ephemeral" }
22
+ expectedColumnNames := []string {"username" , "email" , "name" , "ephemeral" , "path" }
23
23
for i , column := range columns {
24
24
assert .Equal (t , expectedColumnNames [i ], column .Name )
25
25
}
@@ -61,6 +61,12 @@ func TestGenerateForPath(t *testing.T) {
61
61
// Create a temporary directory for testing
62
62
tempDir := t .TempDir ()
63
63
64
+ // Create a placeholder directory for one of the profiles - the name is the
65
+ // info_cache map key, not the 'name' value
66
+ profile1Path := filepath .Join (tempDir , "profile1" )
67
+ err := os .Mkdir (profile1Path , os .ModePerm )
68
+ assert .NoError (t , err )
69
+
64
70
// Create a test Chrome local state file
65
71
localStateFile := filepath .Join (tempDir , "Local State" )
66
72
localStateData := `{
@@ -80,7 +86,7 @@ func TestGenerateForPath(t *testing.T) {
80
86
}
81
87
}`
82
88
83
- err : = os .WriteFile (localStateFile , []byte (localStateData ), os .ModePerm )
89
+ err = os .WriteFile (localStateFile , []byte (localStateData ), os .ModePerm )
84
90
assert .NoError (t , err )
85
91
86
92
// Test generateForPath
@@ -99,14 +105,42 @@ func TestGenerateForPath(t *testing.T) {
99
105
100
106
"name" : "Profile 1" ,
101
107
"ephemeral" : "0" ,
108
+ "path" : profile1Path ,
102
109
},
103
110
{
104
111
"username" : "testuser" ,
105
112
106
113
"name" : "Profile 2" ,
107
114
"ephemeral" : "1" ,
115
+ // this profile directory doesn't exist, so the path should be blank
116
+ "path" : "" ,
108
117
},
109
118
}
110
119
111
120
assert .ElementsMatch (t , expectedProfiles , results )
112
121
}
122
+
123
+ func TestProfilePathStat (t * testing.T ) {
124
+ t .Run ("profile directory exists" , func (t * testing.T ) {
125
+ tempDir := t .TempDir ()
126
+
127
+ localStatePath := filepath .Join (tempDir , "Local State" )
128
+
129
+ profilePath := filepath .Join (tempDir , "profile1" )
130
+ err := os .Mkdir (profilePath , os .ModePerm )
131
+ assert .NoError (t , err )
132
+
133
+ actual , err := profilePathStat (localStatePath , "profile1" )
134
+ assert .NoError (t , err )
135
+ assert .Equal (t , profilePath , actual )
136
+ })
137
+
138
+ t .Run ("profile directory does not exist" , func (t * testing.T ) {
139
+ tempDir := t .TempDir ()
140
+
141
+ localStatePath := filepath .Join (tempDir , "Local State" )
142
+
143
+ _ , err := profilePathStat (localStatePath , "profile-does-not-exist" )
144
+ assert .ErrorIs (t , err , os .ErrNotExist )
145
+ })
146
+ }
0 commit comments