Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 277ba75

Browse files
committed
rename func, improve comments
- `project.go` - Rename method {checkCfgFilenames => checkGopkgFilenames} - Improve funciton comment as suggested by @sdboyer - Fix ambigious comment explaining rationale behind early return. - Add comment explaining why we do not use `fs.IsCaseSensitiveFilesystem` for skipping following tests: - context_test.go#TestLoadProjectGopkgFilenames - project_test.go#TestCheckGopkgFilenames - fs_test.go#TestReadActualFilenames
1 parent 5b2e0d0 commit 277ba75

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *Ctx) LoadProject() (*Project, error) {
105105
return nil, err
106106
}
107107

108-
err = checkCfgFilenames(root)
108+
err = checkGopkgFilenames(root)
109109
if err != nil {
110110
return nil, err
111111
}

context_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,20 @@ func TestLoadProjectNoSrcDir(t *testing.T) {
264264
}
265265
}
266266

267-
func TestLoadProjectCfgFileCase(t *testing.T) {
267+
func TestLoadProjectGopkgFilenames(t *testing.T) {
268+
// We are trying to skip this test on file systems which are case-sensiive. We could
269+
// have used `fs.IsCaseSensitiveFilesystem` for this check. However, the code we are
270+
// testing also relies on `fs.IsCaseSensitiveFilesystem`. So a bug in
271+
// `fs.IsCaseSensitiveFilesystem` could prevent this test from being run. This is the
272+
// only scenario where we prefer the OS heuristic over doing the actual work of
273+
// validating filesystem case sensitivity via `fs.IsCaseSensitiveFilesystem`.
268274
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
269275
t.Skip("skip this test on non-Windows, non-macOS")
270276
}
271277

272278
// Here we test that a manifest filename with incorrect case throws an error. Similar
273279
// error will also be thrown for the lock file as well which has been tested in
274-
// `project_test.go#TestCheckCfgFilenames`. So not repeating here.
280+
// `project_test.go#TestCheckGopkgFilenames`. So not repeating here.
275281

276282
h := test.NewHelper(t)
277283
defer h.Cleanup()

internal/fs/fs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ var errPathNotDir = errors.New("given path is not a directory")
272272
// `os.Stat` and return a map with key and value as filenames which exist in the folder.
273273
//
274274
// Otherwise, it reads the contents of the directory and returns a map which has the
275-
// given file name as the key and actual filename as the value if it was found.
275+
// given file name as the key and actual filename as the value(if it was found).
276276
func ReadActualFilenames(dirPath string, names []string) (map[string]string, error) {
277277
actualFilenames := make(map[string]string, len(names))
278278
if len(names) == 0 {

internal/fs/fs_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ func TestIsCaseSensitiveFilesystem(t *testing.T) {
265265
}
266266

267267
func TestReadActualFilenames(t *testing.T) {
268+
// We are trying to skip this test on file systems which are case-sensiive. We could
269+
// have used `fs.IsCaseSensitiveFilesystem` for this check. However, the code we are
270+
// testing also relies on `fs.IsCaseSensitiveFilesystem`. So a bug in
271+
// `fs.IsCaseSensitiveFilesystem` could prevent this test from being run. This is the
272+
// only scenario where we prefer the OS heuristic over doing the actual work of
273+
// validating filesystem case sensitivity via `fs.IsCaseSensitiveFilesystem`.
268274
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
269275
t.Skip("skip this test on non-Windows, non-macOS")
270276
}
@@ -332,7 +338,8 @@ func TestReadActualFilenames(t *testing.T) {
332338
t.Fatalf("unexpected error: %+v", err)
333339
}
334340
if !reflect.DeepEqual(c.want, got) {
335-
t.Fatalf("returned value does not match expected: \n\t(GOT) %v\n\t(WNT) %v", got, c.want)
341+
t.Fatalf("returned value does not match expected: \n\t(GOT) %v\n\t(WNT) %v",
342+
got, c.want)
336343
}
337344
}
338345
}

project.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@ func findProjectRoot(from string) (string, error) {
4242
}
4343
}
4444

45-
// checkCfgFilenames validates filename case for the manifest and lock files.
45+
// checkGopkgFilenames validates filename case for the manifest and lock files.
4646
//
47-
// This is relevant on case-insensitive file systems like Windows and macOS.
47+
// This is relevant on case-insensitive file systems like the defaults in Windows and
48+
// macOS.
4849
//
4950
// If manifest file is not found, it returns an error indicating the project could not be
5051
// found. If it is found but the case does not match, an error is returned. If a lock
5152
// file is not found, no error is returned as lock file is optional. If it is found but
5253
// the case does not match, an error is returned.
53-
func checkCfgFilenames(projectRoot string) error {
54-
// ReadActualFilenames is actually costly. Since this check is not relevant to
55-
// case-sensitive filesystems like ext4(linux), try for an early return.
54+
func checkGopkgFilenames(projectRoot string) error {
55+
// ReadActualFilenames is actually costly. Since the check to validate filename case
56+
// for Gopkg filenames is not relevant to case-sensitive filesystems like
57+
// ext4(linux), try for an early return.
5658
caseSensitive, err := fs.IsCaseSensitiveFilesystem(projectRoot)
5759
if err != nil {
5860
return errors.Wrap(err, "could not check validity of configuration filenames")

project_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ func TestFindRoot(t *testing.T) {
6363
}
6464
}
6565

66-
func TestCheckCfgFilenames(t *testing.T) {
66+
func TestCheckGopkgFilenames(t *testing.T) {
67+
// We are trying to skip this test on file systems which are case-sensiive. We could
68+
// have used `fs.IsCaseSensitiveFilesystem` for this check. However, the code we are
69+
// testing also relies on `fs.IsCaseSensitiveFilesystem`. So a bug in
70+
// `fs.IsCaseSensitiveFilesystem` could prevent this test from being run. This is the
71+
// only scenario where we prefer the OS heuristic over doing the actual work of
72+
// validating filesystem case sensitivity via `fs.IsCaseSensitiveFilesystem`.
6773
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
6874
t.Skip("skip this test on non-Windows, non-macOS")
6975
}
@@ -111,11 +117,11 @@ func TestCheckCfgFilenames(t *testing.T) {
111117
tmpPath := h.Path(".")
112118

113119
// Create any files that are needed for the test before invoking
114-
// `checkCfgFilenames`.
120+
// `checkGopkgFilenames`.
115121
for _, file := range c.createFiles {
116122
h.TempFile(file, "")
117123
}
118-
err := checkCfgFilenames(tmpPath)
124+
err := checkGopkgFilenames(tmpPath)
119125

120126
if c.wantErr {
121127
if err == nil {

0 commit comments

Comments
 (0)