-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a6026f
commit 8b1a9db
Showing
4 changed files
with
63 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package approvals | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"sync" | ||
|
||
"github.com/approvals/go-approval-tests/utils" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
instance *approvedFileLog | ||
) | ||
|
||
type approvedFileLog struct { | ||
filename string | ||
} | ||
|
||
const approvalTempdirectory = ".approval_tests_temp" | ||
|
||
func GetApprovedFileLoggerInstance() *approvedFileLog { | ||
|
||
once.Do(func() { | ||
instance = &approvedFileLog{ | ||
filename: approvalTempdirectory + "/.approved_files.log", | ||
} | ||
instance.initializeFile() | ||
}) | ||
|
||
return instance | ||
} | ||
|
||
func (l approvedFileLog) initializeFile() { | ||
|
||
// create the file and setup the parent directory if needed | ||
err := os.MkdirAll(approvalTempdirectory, os.ModePerm) | ||
if err != nil { | ||
fmt.Println("Error creating directory: ", err) | ||
return | ||
} | ||
|
||
// create the file and make it executable in one step | ||
file, err := os.OpenFile(l.filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) | ||
if err != nil { | ||
fmt.Println("Error creating file: ", err) | ||
return | ||
} | ||
|
||
file.Close() | ||
|
||
} | ||
|
||
func (l approvedFileLog) Log(approvedFile string) { | ||
// get the absolute path of approvedFile | ||
approvedFile, _ = filepath.Abs(approvedFile) | ||
|
||
utils.AppendToFile(l.filename, approvedFile+"\n") | ||
} |
19 changes: 0 additions & 19 deletions
19
testdata/date_scrubber_test.TestSupportedFormats.approved.md
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
testdata/scrubber_test.TestVerifyDoesNotAcceptSeveralVerifyOptions.approved.txt
This file was deleted.
Oops, something went wrong.