fix mod name, added tests

This commit is contained in:
2023-03-20 14:34:39 +01:00
parent ed9b8ba70d
commit b8816f910a
15 changed files with 182 additions and 25 deletions

View File

@@ -23,9 +23,10 @@ import (
"fmt"
//"github.com/alecthomas/repr"
"github.com/imroc/req/v3"
"github.com/jarcoal/httpmock"
"github.com/schollz/progressbar/v3"
"github.com/tlinden/cenophane/common"
"github.com/tlinden/up/upctl/cfg"
"github.com/tlinden/cenophane/upctl/cfg"
"mime"
"os"
"path/filepath"
@@ -79,6 +80,11 @@ func Setup(c *cfg.Config, path string) *Request {
client.SetCommonBearerAuthToken(c.Apikey)
}
if c.Mock {
// intercept, used by unit tests
httpmock.ActivateNonDefault(client.GetClient())
}
return &Request{Url: c.Endpoint + path, R: R}
}
@@ -123,19 +129,21 @@ func UploadFiles(c *cfg.Config, args []string) error {
return err
}
// progres bar
bar := progressbar.Default(100)
var left float64
if !c.Silent {
// progres bar
bar := progressbar.Default(100)
var left float64
rq.R.SetUploadCallbackWithInterval(func(info req.UploadInfo) {
left = float64(info.UploadedSize) / float64(info.FileSize) * 100.0
bar.Add(int(left))
}, 10*time.Millisecond)
}
// actual post w/ settings
resp, err := rq.R.
SetFormData(map[string]string{
"expire": c.Expire,
}).
SetUploadCallbackWithInterval(func(info req.UploadInfo) {
left = float64(info.UploadedSize) / float64(info.FileSize) * 100.0
bar.Add(int(left))
}, 10*time.Millisecond).
Post(rq.Url)
if err != nil {