| 1 | package tq |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/git-lfs/git-lfs/v3/lfsapi" |
| 7 | "github.com/git-lfs/git-lfs/v3/lfshttp" |
| 8 | "github.com/stretchr/testify/assert" |
| 9 | ) |
| 10 | |
| 11 | func TestCustomTransferBasicConfig(t *testing.T) { |
| 12 | path := "/path/to/binary" |
| 13 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 14 | "lfs.customtransfer.testsimple.path": path, |
| 15 | })) |
| 16 | defer cli.Close() |
| 17 | |
| 18 | m := NewManifest(nil, cli, "", "") |
| 19 | u := m.NewUploadAdapter("testsimple") |
| 20 | assert.NotNil(t, u, "Upload adapter should be present") |
| 21 | cu, _ := u.(*customAdapter) |
| 22 | assert.NotNil(t, cu, "Upload adapter should be customAdapter") |
| 23 | assert.Equal(t, cu.path, path, "Path should be correct") |
| 24 | assert.Equal(t, cu.args, "", "args should be blank") |
| 25 | assert.Equal(t, cu.concurrent, true, "concurrent should be defaulted") |
| 26 | |
| 27 | d := m.NewDownloadAdapter("testsimple") |
| 28 | assert.NotNil(t, d, "Download adapter should be present") |
| 29 | cd, _ := u.(*customAdapter) |
| 30 | assert.NotNil(t, cd, "Download adapter should be customAdapter") |
| 31 | assert.Equal(t, cd.path, path, "Path should be correct") |
| 32 | assert.Equal(t, cd.args, "", "args should be blank") |
| 33 | assert.Equal(t, cd.concurrent, true, "concurrent should be defaulted") |
| 34 | } |
| 35 | |
| 36 | func TestCustomTransferDownloadConfig(t *testing.T) { |
| 37 | path := "/path/to/binary" |
| 38 | args := "-c 1 --whatever" |
| 39 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 40 | "lfs.customtransfer.testdownload.path": path, |
| 41 | "lfs.customtransfer.testdownload.args": args, |
| 42 | "lfs.customtransfer.testdownload.concurrent": "false", |
| 43 | "lfs.customtransfer.testdownload.direction": "download", |
| 44 | })) |
| 45 | defer cli.Close() |
| 46 | |
| 47 | m := NewManifest(nil, cli, "", "") |
| 48 | u := m.NewUploadAdapter("testdownload") |
| 49 | assert.NotNil(t, u, "Upload adapter should always be created") |
| 50 | cu, _ := u.(*customAdapter) |
| 51 | assert.Nil(t, cu, "Upload adapter should NOT be custom (default to basic)") |
| 52 | |
| 53 | d := m.NewDownloadAdapter("testdownload") |
| 54 | assert.NotNil(t, d, "Download adapter should be present") |
| 55 | cd, _ := d.(*customAdapter) |
| 56 | assert.NotNil(t, cd, "Download adapter should be customAdapter") |
| 57 | assert.Equal(t, cd.path, path, "Path should be correct") |
| 58 | assert.Equal(t, cd.args, args, "args should be correct") |
| 59 | assert.Equal(t, cd.concurrent, false, "concurrent should be set") |
| 60 | } |
| 61 | |
| 62 | func TestCustomTransferUploadConfig(t *testing.T) { |
| 63 | path := "/path/to/binary" |
| 64 | args := "-c 1 --whatever" |
| 65 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 66 | "lfs.customtransfer.testupload.path": path, |
| 67 | "lfs.customtransfer.testupload.args": args, |
| 68 | "lfs.customtransfer.testupload.concurrent": "false", |
| 69 | "lfs.customtransfer.testupload.direction": "upload", |
| 70 | })) |
| 71 | defer cli.Close() |
| 72 | |
| 73 | m := NewManifest(nil, cli, "", "") |
| 74 | d := m.NewDownloadAdapter("testupload") |
| 75 | assert.NotNil(t, d, "Download adapter should always be created") |
| 76 | cd, _ := d.(*customAdapter) |
| 77 | assert.Nil(t, cd, "Download adapter should NOT be custom (default to basic)") |
| 78 | |
| 79 | u := m.NewUploadAdapter("testupload") |
| 80 | assert.NotNil(t, u, "Upload adapter should be present") |
| 81 | cu, _ := u.(*customAdapter) |
| 82 | assert.NotNil(t, cu, "Upload adapter should be customAdapter") |
| 83 | assert.Equal(t, cu.path, path, "Path should be correct") |
| 84 | assert.Equal(t, cu.args, args, "args should be correct") |
| 85 | assert.Equal(t, cu.concurrent, false, "concurrent should be set") |
| 86 | } |
| 87 | |
| 88 | func TestCustomTransferBothConfig(t *testing.T) { |
| 89 | path := "/path/to/binary" |
| 90 | args := "-c 1 --whatever --yeah" |
| 91 | cli := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 92 | "lfs.customtransfer.testboth.path": path, |
| 93 | "lfs.customtransfer.testboth.args": args, |
| 94 | "lfs.customtransfer.testboth.concurrent": "yes", |
| 95 | "lfs.customtransfer.testboth.direction": "both", |
| 96 | })) |
| 97 | defer cli.Close() |
| 98 | |
| 99 | m := NewManifest(nil, cli, "", "") |
| 100 | d := m.NewDownloadAdapter("testboth") |
| 101 | assert.NotNil(t, d, "Download adapter should be present") |
| 102 | cd, _ := d.(*customAdapter) |
| 103 | assert.NotNil(t, cd, "Download adapter should be customAdapter") |
| 104 | assert.Equal(t, cd.path, path, "Path should be correct") |
| 105 | assert.Equal(t, cd.args, args, "args should be correct") |
| 106 | assert.Equal(t, cd.concurrent, true, "concurrent should be set") |
| 107 | |
| 108 | u := m.NewUploadAdapter("testboth") |
| 109 | assert.NotNil(t, u, "Upload adapter should be present") |
| 110 | cu, _ := u.(*customAdapter) |
| 111 | assert.NotNil(t, cu, "Upload adapter should be customAdapter") |
| 112 | assert.Equal(t, cu.path, path, "Path should be correct") |
| 113 | assert.Equal(t, cu.args, args, "args should be correct") |
| 114 | assert.Equal(t, cu.concurrent, true, "concurrent should be set") |
| 115 | } |