@@ -24,7 +24,7 @@ func TestDefaultStorePath(t *testing.T) {
2424 expected = filepath .Join (home , ".password-store" )
2525 actual , _ = defaultStorePath ()
2626 if expected != actual {
27- t .Errorf ("%s does not match %s " , expected , actual )
27+ t .Errorf ("1: '%s' does not match '%s' " , expected , actual )
2828 }
2929
3030 // custom directory from $PASSWORD_STORE_DIR
@@ -36,9 +36,12 @@ func TestDefaultStorePath(t *testing.T) {
3636 fmt .Println (expected )
3737 os .Mkdir (expected , os .ModePerm )
3838 os .Setenv ("PASSWORD_STORE_DIR" , expected )
39- actual , _ = defaultStorePath ()
39+ actual , err = defaultStorePath ()
40+ if err != nil {
41+ t .Error (err )
42+ }
4043 if expected != actual {
41- t .Errorf ("%s does not match %s " , expected , actual )
44+ t .Errorf ("2: '%s' does not match '%s' " , expected , actual )
4245 }
4346
4447 // clean-up
@@ -63,7 +66,7 @@ func TestDiskStore_Search_nomatch(t *testing.T) {
6366}
6467
6568func TestDiskStoreSearch (t * testing.T ) {
66- store := diskStore {"test_store" }
69+ store := diskStore {"test_store" , false }
6770 targetDomain := "abc.com"
6871 testDomains := []string {"abc.com" , "test.abc.com" , "testing.test.abc.com" }
6972 for _ , domain := range testDomains {
@@ -86,7 +89,7 @@ func TestDiskStoreSearch(t *testing.T) {
8689}
8790
8891func TestDiskStoreSearchNoDuplicatesWhenPatternMatchesDomainAndUsername (t * testing.T ) {
89- store := diskStore {"test_store" }
92+ store := diskStore {"test_store" , false }
9093 searchResult , err := store .Search ("xyz" )
9194 if err != nil {
9295 t .Fatal (err )
@@ -101,7 +104,7 @@ func TestDiskStoreSearchNoDuplicatesWhenPatternMatchesDomainAndUsername(t *testi
101104}
102105
103106func TestDiskStoreSearchFollowsSymlinkFiles (t * testing.T ) {
104- store := diskStore {"test_store" }
107+ store := diskStore {"test_store" , false }
105108 searchResult , err := store .Search ("def.com" )
106109 if err != nil {
107110 t .Fatal (err )
@@ -116,7 +119,7 @@ func TestDiskStoreSearchFollowsSymlinkFiles(t *testing.T) {
116119}
117120
118121func TestDiskStoreSearchFollowsSymlinkDirectories (t * testing.T ) {
119- store := diskStore {"test_store" }
122+ store := diskStore {"test_store" , false }
120123 searchResult , err := store .Search ("amazon.co.uk" )
121124 if err != nil {
122125 t .Fatal (err )
@@ -131,7 +134,7 @@ func TestDiskStoreSearchFollowsSymlinkDirectories(t *testing.T) {
131134}
132135
133136func TestDiskStoreSearchSubDirectories (t * testing.T ) {
134- store := diskStore {"test_store" }
137+ store := diskStore {"test_store" , false }
135138 searchTermsMatches := map [string ][]string {
136139 "abc.org" : []string {"abc.org/user3" , "abc.org/wiki/user4" , "abc.org/wiki/work/user5" },
137140 "wiki" : []string {"abc.org/wiki/user4" , "abc.org/wiki/work/user5" },
@@ -155,7 +158,7 @@ func TestDiskStoreSearchSubDirectories(t *testing.T) {
155158}
156159
157160func TestDiskStorePartSearch (t * testing.T ) {
158- store := diskStore {"test_store" }
161+ store := diskStore {"test_store" , false }
159162 searchResult , err := store .Search ("ab" )
160163 if err != nil {
161164 t .Fatal (err )
@@ -170,3 +173,60 @@ func TestDiskStorePartSearch(t *testing.T) {
170173 }
171174 }
172175}
176+
177+ func TestFuzzySearch (t * testing.T ) {
178+ store := diskStore {"test_store" , true }
179+ searchResult , err := store .Search ("amaz2" )
180+
181+ if err != nil {
182+ t .Fatal (err )
183+ }
184+ if len (searchResult ) != 2 {
185+ t .Fatalf ("Result size was: %s expected 2" , len (searchResult ))
186+ }
187+
188+ expectedResult := map [string ]bool {
189+ "amazon.co.uk/user2" : true ,
190+ "amazon.com/user2" : true ,
191+ }
192+
193+ for _ , res := range searchResult {
194+ if ! expectedResult [res ] {
195+ t .Fatalf ("Result %s not expected!" , res )
196+ }
197+ }
198+ }
199+
200+ func TestFuzzySearchNoResult (t * testing.T ) {
201+ store := diskStore {"test_store" , true }
202+ searchResult , err := store .Search ("vvv" )
203+
204+ if err != nil {
205+ t .Fatal (err )
206+ }
207+ if len (searchResult ) != 0 {
208+ t .Fatalf ("Result size was: %s expected 0" , len (searchResult ))
209+ }
210+ }
211+
212+ func TestFuzzySearchTopLevelEntries (t * testing.T ) {
213+ store := diskStore {"test_store" , true }
214+ searchResult , err := store .Search ("def" )
215+
216+ if err != nil {
217+ t .Fatal (err )
218+ }
219+ if len (searchResult ) != 1 {
220+ t .Fatalf ("Result size was: %s expected 1" , len (searchResult ))
221+ }
222+
223+ expectedResult := map [string ]bool {
224+ "def.com" : true ,
225+ }
226+
227+ for _ , res := range searchResult {
228+ if ! expectedResult [res ] {
229+ t .Fatalf ("Result %s not expected!" , res )
230+ }
231+ }
232+ }
0 commit comments