2016-12-12 00:28:47 +00:00
|
|
|
package tq
|
2016-07-08 11:46:04 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-01-04 16:05:29 +00:00
|
|
|
"github.com/git-lfs/git-lfs/lfsapi"
|
2018-09-06 21:42:41 +00:00
|
|
|
"github.com/git-lfs/git-lfs/lfshttp"
|
2016-08-09 21:43:29 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-01-04 16:05:29 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-07-08 11:46:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCustomTransferBasicConfig(t *testing.T) {
|
|
|
|
path := "/path/to/binary"
|
2018-09-06 21:42:41 +00:00
|
|
|
cli, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
|
2017-01-04 16:05:29 +00:00
|
|
|
"lfs.customtransfer.testsimple.path": path,
|
|
|
|
}))
|
|
|
|
require.Nil(t, err)
|
2016-07-08 11:46:04 +00:00
|
|
|
|
2017-10-25 17:46:37 +00:00
|
|
|
m := NewManifest(nil, cli, "", "")
|
2016-08-09 21:43:29 +00:00
|
|
|
u := m.NewUploadAdapter("testsimple")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, u, "Upload adapter should be present")
|
|
|
|
cu, _ := u.(*customAdapter)
|
|
|
|
assert.NotNil(t, cu, "Upload adapter should be customAdapter")
|
|
|
|
assert.Equal(t, cu.path, path, "Path should be correct")
|
|
|
|
assert.Equal(t, cu.args, "", "args should be blank")
|
|
|
|
assert.Equal(t, cu.concurrent, true, "concurrent should be defaulted")
|
|
|
|
|
2016-08-09 21:43:29 +00:00
|
|
|
d := m.NewDownloadAdapter("testsimple")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, d, "Download adapter should be present")
|
|
|
|
cd, _ := u.(*customAdapter)
|
|
|
|
assert.NotNil(t, cd, "Download adapter should be customAdapter")
|
|
|
|
assert.Equal(t, cd.path, path, "Path should be correct")
|
|
|
|
assert.Equal(t, cd.args, "", "args should be blank")
|
|
|
|
assert.Equal(t, cd.concurrent, true, "concurrent should be defaulted")
|
|
|
|
}
|
|
|
|
|
2016-08-10 14:41:14 +00:00
|
|
|
func TestCustomTransferDownloadConfig(t *testing.T) {
|
2016-07-08 11:46:04 +00:00
|
|
|
path := "/path/to/binary"
|
|
|
|
args := "-c 1 --whatever"
|
2018-09-06 21:42:41 +00:00
|
|
|
cli, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
|
2017-01-04 16:05:29 +00:00
|
|
|
"lfs.customtransfer.testdownload.path": path,
|
|
|
|
"lfs.customtransfer.testdownload.args": args,
|
|
|
|
"lfs.customtransfer.testdownload.concurrent": "false",
|
|
|
|
"lfs.customtransfer.testdownload.direction": "download",
|
|
|
|
}))
|
|
|
|
require.Nil(t, err)
|
2016-08-09 21:43:29 +00:00
|
|
|
|
2017-10-25 17:46:37 +00:00
|
|
|
m := NewManifest(nil, cli, "", "")
|
2016-08-09 21:43:29 +00:00
|
|
|
u := m.NewUploadAdapter("testdownload")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, u, "Upload adapter should always be created")
|
|
|
|
cu, _ := u.(*customAdapter)
|
|
|
|
assert.Nil(t, cu, "Upload adapter should NOT be custom (default to basic)")
|
|
|
|
|
2016-08-09 21:43:29 +00:00
|
|
|
d := m.NewDownloadAdapter("testdownload")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, d, "Download adapter should be present")
|
|
|
|
cd, _ := d.(*customAdapter)
|
|
|
|
assert.NotNil(t, cd, "Download adapter should be customAdapter")
|
|
|
|
assert.Equal(t, cd.path, path, "Path should be correct")
|
|
|
|
assert.Equal(t, cd.args, args, "args should be correct")
|
|
|
|
assert.Equal(t, cd.concurrent, false, "concurrent should be set")
|
|
|
|
}
|
|
|
|
|
2016-08-10 14:41:14 +00:00
|
|
|
func TestCustomTransferUploadConfig(t *testing.T) {
|
2016-07-08 11:46:04 +00:00
|
|
|
path := "/path/to/binary"
|
|
|
|
args := "-c 1 --whatever"
|
2018-09-06 21:42:41 +00:00
|
|
|
cli, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
|
2017-01-04 16:05:29 +00:00
|
|
|
"lfs.customtransfer.testupload.path": path,
|
|
|
|
"lfs.customtransfer.testupload.args": args,
|
|
|
|
"lfs.customtransfer.testupload.concurrent": "false",
|
|
|
|
"lfs.customtransfer.testupload.direction": "upload",
|
|
|
|
}))
|
|
|
|
require.Nil(t, err)
|
2016-08-09 21:43:29 +00:00
|
|
|
|
2017-10-25 17:46:37 +00:00
|
|
|
m := NewManifest(nil, cli, "", "")
|
2016-08-09 21:43:29 +00:00
|
|
|
d := m.NewDownloadAdapter("testupload")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, d, "Download adapter should always be created")
|
|
|
|
cd, _ := d.(*customAdapter)
|
|
|
|
assert.Nil(t, cd, "Download adapter should NOT be custom (default to basic)")
|
|
|
|
|
2016-08-09 21:43:29 +00:00
|
|
|
u := m.NewUploadAdapter("testupload")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, u, "Upload adapter should be present")
|
|
|
|
cu, _ := u.(*customAdapter)
|
|
|
|
assert.NotNil(t, cu, "Upload adapter should be customAdapter")
|
|
|
|
assert.Equal(t, cu.path, path, "Path should be correct")
|
|
|
|
assert.Equal(t, cu.args, args, "args should be correct")
|
|
|
|
assert.Equal(t, cu.concurrent, false, "concurrent should be set")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCustomTransferBothConfig(t *testing.T) {
|
|
|
|
path := "/path/to/binary"
|
|
|
|
args := "-c 1 --whatever --yeah"
|
2018-09-06 21:42:41 +00:00
|
|
|
cli, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
|
2017-01-04 16:05:29 +00:00
|
|
|
"lfs.customtransfer.testboth.path": path,
|
|
|
|
"lfs.customtransfer.testboth.args": args,
|
|
|
|
"lfs.customtransfer.testboth.concurrent": "yes",
|
|
|
|
"lfs.customtransfer.testboth.direction": "both",
|
|
|
|
}))
|
|
|
|
require.Nil(t, err)
|
2016-08-09 21:43:29 +00:00
|
|
|
|
2017-10-25 17:46:37 +00:00
|
|
|
m := NewManifest(nil, cli, "", "")
|
2016-08-09 21:43:29 +00:00
|
|
|
d := m.NewDownloadAdapter("testboth")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, d, "Download adapter should be present")
|
|
|
|
cd, _ := d.(*customAdapter)
|
|
|
|
assert.NotNil(t, cd, "Download adapter should be customAdapter")
|
|
|
|
assert.Equal(t, cd.path, path, "Path should be correct")
|
|
|
|
assert.Equal(t, cd.args, args, "args should be correct")
|
|
|
|
assert.Equal(t, cd.concurrent, true, "concurrent should be set")
|
|
|
|
|
2016-08-09 21:43:29 +00:00
|
|
|
u := m.NewUploadAdapter("testboth")
|
2016-07-08 11:46:04 +00:00
|
|
|
assert.NotNil(t, u, "Upload adapter should be present")
|
|
|
|
cu, _ := u.(*customAdapter)
|
|
|
|
assert.NotNil(t, cu, "Upload adapter should be customAdapter")
|
|
|
|
assert.Equal(t, cu.path, path, "Path should be correct")
|
|
|
|
assert.Equal(t, cu.args, args, "args should be correct")
|
|
|
|
assert.Equal(t, cu.concurrent, true, "concurrent should be set")
|
|
|
|
}
|