-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disk: separate most tests from package
Separate most disk tests into internal and external ones. - disk_test.go: was internal (package disk) and is now external (package disk_test) - Function `entityPath()` and method `PartitionTable.findDirectoryEntityPath()` are now exported for tests in export_test.go - Test partition tables moved to partition_table_internal_test.go and exported. - Unique string tests moved to new file: disk_internal_test.go
- Loading branch information
1 parent
020794b
commit 4c626ac
Showing
4 changed files
with
560 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package disk | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGenUniqueString(t *testing.T) { | ||
type testCase struct { | ||
base string | ||
existing map[string]bool | ||
exp string | ||
} | ||
|
||
testCases := map[string]testCase{ | ||
"simple": { | ||
base: "root", | ||
existing: map[string]bool{ | ||
"one": true, | ||
"two": true, | ||
}, | ||
exp: "root", | ||
}, | ||
"collision": { | ||
base: "root", | ||
existing: map[string]bool{ | ||
"one": true, | ||
"two": true, | ||
"root": true, | ||
}, | ||
exp: "root00", | ||
}, | ||
"collision-2": { | ||
base: "word", | ||
existing: map[string]bool{ | ||
"word": true, | ||
"word00": true, | ||
"word01": true, | ||
"other": true, | ||
}, | ||
exp: "word02", | ||
}, | ||
} | ||
|
||
for name := range testCases { | ||
tc := testCases[name] | ||
t.Run(name, func(t *testing.T) { | ||
assert := assert.New(t) | ||
out, err := genUniqueString(tc.base, tc.existing) | ||
assert.NoError(err) | ||
assert.Equal(tc.exp, out) | ||
}) | ||
} | ||
} | ||
|
||
func TestGenUniqueStringManyCollisions(t *testing.T) { | ||
type testCase struct { | ||
base string | ||
ncollisions int | ||
exp string | ||
errmsg string | ||
} | ||
|
||
testCases := map[string]testCase{ | ||
"baseword33": { | ||
base: "baseword", | ||
ncollisions: 33, | ||
exp: "baseword33", | ||
}, | ||
"somany99": { | ||
base: "somany", | ||
ncollisions: 99, | ||
exp: "somany99", | ||
}, | ||
"tk42102": { | ||
base: "tk421", | ||
ncollisions: 2, | ||
exp: "tk42102", | ||
}, | ||
"so-many-collisions": { | ||
base: "all-the-collisions", | ||
ncollisions: 100, | ||
errmsg: `name collision: could not generate unique version of "all-the-collisions"`, | ||
}, | ||
} | ||
|
||
for name := range testCases { | ||
tc := testCases[name] | ||
t.Run(name, func(t *testing.T) { | ||
assert := assert.New(t) | ||
existing := map[string]bool{ | ||
tc.base: true, | ||
} | ||
for n := 0; n < tc.ncollisions; n++ { | ||
existing[fmt.Sprintf("%s%02d", tc.base, n)] = true | ||
} | ||
out, err := genUniqueString(tc.base, existing) | ||
if tc.errmsg == "" { | ||
assert.NoError(err) | ||
assert.Equal(tc.exp, out) | ||
} else { | ||
assert.EqualError(err, tc.errmsg) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.