-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve IO performance Add caching for IO operations Fix dependency caching Add cache by modifietAt filestat, avoiding checksums
- Loading branch information
Showing
15 changed files
with
250 additions
and
213 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
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
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 |
---|---|---|
@@ -1,19 +1,48 @@ | ||
package fake | ||
|
||
import ( | ||
"go/ast" | ||
"go/token" | ||
"os" | ||
"path" | ||
|
||
"github.com/sonalys/fake/internal/files" | ||
"github.com/sonalys/fake/internal/imports" | ||
"golang.org/x/mod/modfile" | ||
) | ||
|
||
// Generator is the controller for the whole module, caching files and holding metadata. | ||
type Generator struct { | ||
FileSet *token.FileSet | ||
MockPackageName string | ||
|
||
cachedPackageInfo func(f *ast.File) (nameMap, pathMap map[string]*imports.ImportEntry) | ||
goModFilename string | ||
goMod *modfile.File | ||
} | ||
|
||
// NewGenerator will create a new mock generator for the specified module. | ||
func NewGenerator(n string) *Generator { | ||
return &Generator{ | ||
FileSet: token.NewFileSet(), | ||
MockPackageName: n, | ||
func NewGenerator(pkgName, baseDir string) (*Generator, error) { | ||
goModPath, err := files.FindFile(baseDir, "go.mod") | ||
if err != nil { | ||
return nil, err | ||
} | ||
// Read the contents of the go.mod file | ||
modFileContent, err := os.ReadFile(goModPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// Parse the go.mod file | ||
modFile, err := modfile.Parse(goModPath, modFileContent, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Generator{ | ||
FileSet: token.NewFileSet(), | ||
goModFilename: goModPath, | ||
goMod: modFile, | ||
MockPackageName: pkgName, | ||
cachedPackageInfo: imports.CachedImportInformation(path.Dir(goModPath)), | ||
}, nil | ||
} |
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
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
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
Oops, something went wrong.