Files
atlantis/server/core/runtime/models/filepath.go
Ken Kaizu 27b9897517 chore(build): rm pegomock experimental feature for smooth mock generation (#2886)
* disable pegomock --use-experimental-model-gen, cause random fail by segv

* make regen-mocks

* fix mock code which uses non experimental pegomock codes
2022-12-27 19:58:15 -06:00

41 lines
860 B
Go

package models
import (
"os"
"path/filepath"
)
//go:generate pegomock generate -m --package mocks -o mocks/mock_filepath.go FilePath
type FilePath interface {
NotExists() bool
Join(elem ...string) FilePath
Symlink(newname string) (FilePath, error)
Resolve() string
}
type LocalFilePath string
func (fp LocalFilePath) NotExists() bool {
_, err := os.Stat(string(fp))
return os.IsNotExist(err)
}
func (fp LocalFilePath) Join(elem ...string) FilePath {
pathComponents := []string{}
pathComponents = append(pathComponents, string(fp))
pathComponents = append(pathComponents, elem...)
return LocalFilePath(filepath.Join(pathComponents...))
}
func (fp LocalFilePath) Symlink(newname string) (FilePath, error) {
return LocalFilePath(newname), os.Symlink(fp.Resolve(), newname)
}
func (fp LocalFilePath) Resolve() string {
return string(fp)
}