-
Notifications
You must be signed in to change notification settings - Fork 13
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 #13 from InfuseAI/feature/sc-24993/local-repo-enha…
…ncement Local repo support atomic upload
- Loading branch information
Showing
6 changed files
with
193 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTransformRepoUrl(t *testing.T) { | ||
baseDir := "/tmp/artiv" | ||
testCases := []struct { | ||
desc string | ||
in string | ||
out string | ||
}{ | ||
{desc: "local file", in: "/this/is/my/path", out: "/this/is/my/path"}, | ||
{desc: "relative path", in: "../path", out: "/tmp/path"}, | ||
{desc: "relative path2", in: "../../../path", out: "/path"}, | ||
{desc: "normal url (file)", in: "file://mybucket/this/is/my/path", out: "file://mybucket/this/is/my/path"}, | ||
{desc: "normal url (s3)", in: "s3://mybucket/this/is/my/path", out: "s3://mybucket/this/is/my/path"}, | ||
} | ||
|
||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
result, err := transformRepoUrl(baseDir, tC.in) | ||
if err != nil { | ||
assert.Empty(t, tC.out) | ||
} else { | ||
assert.Equal(t, tC.out, result) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package repository | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLocalUpload(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
data string | ||
}{ | ||
{ | ||
desc: "empty file", data: "", | ||
}, | ||
{ | ||
desc: "non empty file", data: "hello", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
repoDir := t.TempDir() | ||
tmpDir := t.TempDir() | ||
|
||
repo, err := NewLocalFileSystemRepository(repoDir) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = os.WriteFile(tmpDir+"/test", []byte(tC.data), 0644) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = repo.Upload(tmpDir+"/test", "path/to/the/test", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
data, err := os.ReadFile(repoDir + "/path/to/the/test") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
assert.Equal(t, []byte(tC.data), []byte(data)) | ||
}) | ||
} | ||
} | ||
|
||
func TestLocalDownload(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
data string | ||
}{ | ||
{ | ||
desc: "empty file", data: "", | ||
}, | ||
{ | ||
desc: "non empty file", data: "hello", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
repoDir := t.TempDir() | ||
tmpDir := t.TempDir() | ||
|
||
repo, err := NewLocalFileSystemRepository(repoDir) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = os.MkdirAll(repoDir+"/path/to/the", os.ModePerm) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = os.WriteFile(repoDir+"/path/to/the/test", []byte(tC.data), 0644) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = repo.Download("path/to/the/test", tmpDir+"/test", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
data, err := os.ReadFile(tmpDir + "/test") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
assert.Equal(t, []byte(tC.data), []byte(data)) | ||
}) | ||
} | ||
} |