Skip to content

Commit

Permalink
Switch to using .MODULE_ROOT anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
dsoprea committed Jun 4, 2020
1 parent 3937388 commit 7d5993c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 45 deletions.
Empty file added .MODULE_ROOT
Empty file.
45 changes: 0 additions & 45 deletions common_test.go

This file was deleted.

64 changes: 64 additions & 0 deletions testing_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package tiffstructure

import (
"os"
"path"

"github.com/dsoprea/go-logging"
)

var (
assetsPath = ""
)

// getModuleRootPath returns our source-path when running from source during
// tests.
func getModuleRootPath() string {
moduleRootPath := os.Getenv("TIFF_MODULE_ROOT_PATH")
if moduleRootPath != "" {
return moduleRootPath
}

currentWd, err := os.Getwd()
log.PanicIf(err)

currentPath := currentWd
visited := make([]string, 0)

for {
tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")

_, err := os.Stat(tryStampFilepath)
if err != nil && os.IsNotExist(err) != true {
log.Panic(err)
} else if err == nil {
break
}

visited = append(visited, tryStampFilepath)

currentPath = path.Dir(currentPath)
if currentPath == "/" {
log.Panicf("could not find module-root: %v", visited)
}
}

return currentPath
}

// getTestAssetsPath returns the test-asset path.
func getTestAssetsPath() string {
if assetsPath == "" {
moduleRootPath := getModuleRootPath()
assetsPath = path.Join(moduleRootPath, "assets")
}

return assetsPath
}

// getTestExifImageFilepath returns the file-path of the default EXIF image
// asset.
func getTestExifImageFilepath() string {
assetsPath := getTestAssetsPath()
return path.Join(assetsPath, "file_example_TIFF_1MB-scaled.tiff")
}

0 comments on commit 7d5993c

Please sign in to comment.