aboutsummaryrefslogtreecommitdiff
path: root/testutil/testutil.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2022-09-10 17:33:30 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2022-09-10 17:33:30 +0200
commit3451d56ead6e57f503962b876c89284f1fb73a90 (patch)
tree172599f1f3acd77bc918c55403eb78255ced43e6 /testutil/testutil.go
parent544bbeeaf836436305cbed87ae1019511de62535 (diff)
downloadporg-3451d56ead6e57f503962b876c89284f1fb73a90.tar.gz
porg-3451d56ead6e57f503962b876c89284f1fb73a90.tar.bz2
porg-3451d56ead6e57f503962b876c89284f1fb73a90.zip
ref: Create a storage interface
This `Storage` interface will define all the interactions with the storage system. For now I plan to support native file system through go's standard library and Nextcloud through *webdav*. So this is the first step in that direction.
Diffstat (limited to 'testutil/testutil.go')
-rw-r--r--testutil/testutil.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/testutil/testutil.go b/testutil/testutil.go
new file mode 100644
index 0000000..3b5f7b5
--- /dev/null
+++ b/testutil/testutil.go
@@ -0,0 +1,50 @@
+package testutil
+
+import (
+ "fmt"
+ "math/rand"
+ "os"
+ "time"
+)
+
+func init() {
+ rand.Seed(time.Now().UnixNano())
+}
+
+func RandomString(n int) string {
+ var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
+ s := make([]rune, n)
+ for i := range s {
+ s[i] = letters[rand.Intn(len(letters))]
+ }
+ return string(s)
+}
+
+func CreateFolder() (tmp string) {
+ tmp = fmt.Sprintf("/tmp/%s", RandomString(10))
+
+ err := os.Mkdir(tmp, 0755)
+
+ if err != nil {
+ fmt.Println(err.Error())
+ }
+
+ return
+}
+
+func AppendEmptyFile(path string) (fullPath string) {
+ fullPath = fmt.Sprintf("%s/%s", path, RandomString(10))
+ os.OpenFile(fullPath, os.O_RDONLY|os.O_CREATE, 0666)
+
+ return
+}
+
+func CreateEmptyFile(path string) {
+ os.OpenFile(path, os.O_RDONLY|os.O_CREATE, 0666)
+}
+
+func CreateTmpFile() (fullPath string) {
+ path := CreateFolder()
+ fullPath = AppendEmptyFile(path)
+ return
+}