Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct file perms on nested snapshot dir #108

Merged
merged 2 commits into from Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion snapshot.go
Expand Up @@ -128,7 +128,7 @@ func SnapshotCreateOrValidate(t testRunner, name string, object interface{}, msg
dir := getCurrentScriptDirectory() + "/testdata/snapshots/"
snapshotPath := path.Clean(dir + name + ".testza")
if strings.Contains(name, "/") {
err := os.MkdirAll(path.Dir(snapshotPath), 0600)
err := os.MkdirAll(path.Dir(snapshotPath), 0755)
if err != nil {
return fmt.Errorf("creating snapshot directories failed: %w", err)
}
Expand Down
21 changes: 21 additions & 0 deletions snapshot_test.go
Expand Up @@ -88,3 +88,24 @@ func TestSnapshotCreateOrValidate_invalid_name(t *testing.T) {
err := testza.SnapshotCreateOrValidate(t, string(rune(0))+"><", snapshotObject)
testza.AssertNotNil(t, err)
}

func TestSnapshotCreateOrValidate_nested_test_name(t *testing.T) {
snapshotNestedDirName := t.Name()
snapshotName := snapshotNestedDirName + "/nested_name"

snapshotFullPath := internal.GetCurrentScriptDirectory() + "/testdata/snapshots/" + snapshotNestedDirName

// ensure snapshot does not exist - remove snapshot and empty parent directory
if _, err := os.Stat(snapshotFullPath); err == nil {
_ = os.RemoveAll(snapshotFullPath)
}

err := testza.SnapshotCreateOrValidate(t, snapshotName, "snapshot-data")

// try to clean up before the assert so we leave the working copy clean
if _, err := os.Stat(snapshotFullPath); err == nil {
_ = os.RemoveAll(snapshotFullPath)
}

testza.AssertNoError(t, err)
}