-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1437 from Luap99/subscription-save
pkg/subscription: fix regression in saveTo()
- Loading branch information
Showing
2 changed files
with
41 additions
and
5 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,32 @@ | ||
package subscriptions | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReadAllAndSaveTo(t *testing.T) { | ||
const testMode = os.FileMode(0o700) | ||
|
||
rootDir := t.TempDir() | ||
childDir := filepath.Join(rootDir, "child") | ||
err := os.Mkdir(childDir, testMode) | ||
assert.NoError(t, err, "mkdir child") | ||
|
||
filePath := "child/file" | ||
err = os.WriteFile(filepath.Join(rootDir, filePath), []byte("test"), testMode) | ||
assert.NoError(t, err, "write file") | ||
|
||
data, err := readAll(rootDir, "", testMode) | ||
assert.NoError(t, err, "readAll") | ||
assert.Len(t, data, 1, "readAll should return one result") | ||
|
||
tmpDir := t.TempDir() | ||
err = data[0].saveTo(tmpDir) | ||
assert.NoError(t, err, "saveTo()") | ||
|
||
assert.FileExists(t, filepath.Join(tmpDir, filePath), "file exists at correct location") | ||
} |