git-lfs/tq/transfer_test.go

175 lines
4.1 KiB
Go
Raw Normal View History

package tq
2016-05-31 10:04:17 +00:00
import (
"testing"
"github.com/git-lfs/git-lfs/v3/lfsapi"
"github.com/git-lfs/git-lfs/v3/lfshttp"
2016-05-31 10:04:17 +00:00
"github.com/stretchr/testify/assert"
2017-01-04 16:05:29 +00:00
"github.com/stretchr/testify/require"
2016-05-31 10:04:17 +00:00
)
type testAdapter struct {
name string
dir Direction
}
func (a *testAdapter) Name() string {
return a.name
}
2016-05-31 10:04:17 +00:00
func (a *testAdapter) Direction() Direction {
return a.dir
}
func (a *testAdapter) Begin(cfg AdapterConfig, cb ProgressCallback) error {
2016-05-31 10:04:17 +00:00
return nil
}
func (a *testAdapter) Add(ts ...*Transfer) (retries <-chan TransferResult) {
return nil
2016-05-31 10:04:17 +00:00
}
2016-05-31 10:04:17 +00:00
func (a *testAdapter) End() {
}
func newTestAdapter(name string, dir Direction) Adapter {
2016-05-31 10:04:17 +00:00
return &testAdapter{name, dir}
}
func newRenamedTestAdapter(name string, dir Direction) Adapter {
2016-05-31 10:04:17 +00:00
return &testAdapter{"RENAMED", dir}
}
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
func TestBasicAdapterExists(t *testing.T) {
2017-10-25 17:46:37 +00:00
m := NewManifest(nil, nil, "", "")
2016-05-31 10:04:17 +00:00
assert := assert.New(t)
dls := m.GetDownloadAdapterNames()
2016-05-31 10:04:17 +00:00
if assert.NotNil(dls) {
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
assert.ElementsMatch([]string{"basic", "lfs-standalone-file", "ssh"}, dls)
2016-05-31 10:04:17 +00:00
}
uls := m.GetUploadAdapterNames()
2016-05-31 10:04:17 +00:00
if assert.NotNil(uls) {
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
assert.ElementsMatch([]string{"basic", "lfs-standalone-file", "ssh"}, dls)
2016-05-31 10:04:17 +00:00
}
da := m.NewDownloadAdapter("basic")
2016-05-31 10:04:17 +00:00
if assert.NotNil(da) {
assert.Equal("basic", da.Name())
assert.Equal(Download, da.Direction())
}
ua := m.NewUploadAdapter("basic")
2016-05-31 10:04:17 +00:00
if assert.NotNil(ua) {
assert.Equal("basic", ua.Name())
assert.Equal(Upload, ua.Direction())
}
}
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
func TestAdapterRegAndOverride(t *testing.T) {
2017-10-25 17:46:37 +00:00
m := NewManifest(nil, nil, "", "")
2016-05-31 10:04:17 +00:00
assert := assert.New(t)
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
assert.Nil(m.NewAdapter("test", Download))
assert.Nil(m.NewAdapter("test", Upload))
da := m.NewDownloadAdapter("test")
if assert.NotNil(da) {
assert.Equal("basic", da.Name())
assert.Equal(Download, da.Direction())
}
ua := m.NewUploadAdapter("test")
if assert.NotNil(ua) {
assert.Equal("basic", ua.Name())
assert.Equal(Upload, ua.Direction())
}
2016-05-31 10:04:17 +00:00
m.RegisterNewAdapterFunc("test", Upload, newTestAdapter)
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
assert.Nil(m.NewAdapter("test", Download))
assert.NotNil(m.NewAdapter("test", Upload))
da = m.NewDownloadAdapter("test")
if assert.NotNil(da) {
assert.Equal("basic", da.Name())
assert.Equal(Download, da.Direction())
}
ua = m.NewUploadAdapter("test")
if assert.NotNil(ua) {
assert.Equal("test", ua.Name())
assert.Equal(Upload, ua.Direction())
}
2016-05-31 10:04:17 +00:00
m.RegisterNewAdapterFunc("test", Download, newTestAdapter)
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
assert.NotNil(m.NewAdapter("test", Download))
assert.NotNil(m.NewAdapter("test", Upload))
da = m.NewDownloadAdapter("test")
2016-05-31 10:04:17 +00:00
if assert.NotNil(da) {
assert.Equal("test", da.Name())
assert.Equal(Download, da.Direction())
}
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
ua = m.NewUploadAdapter("test")
2016-05-31 10:04:17 +00:00
if assert.NotNil(ua) {
assert.Equal("test", ua.Name())
assert.Equal(Upload, ua.Direction())
}
// Test override
m.RegisterNewAdapterFunc("test", Upload, newRenamedTestAdapter)
ua = m.NewUploadAdapter("test")
2016-05-31 10:04:17 +00:00
if assert.NotNil(ua) {
assert.Equal("RENAMED", ua.Name())
assert.Equal(Upload, ua.Direction())
}
da = m.NewDownloadAdapter("test")
2016-05-31 10:04:17 +00:00
if assert.NotNil(da) {
assert.Equal("test", da.Name())
assert.Equal(Download, da.Direction())
}
m.RegisterNewAdapterFunc("test", Download, newRenamedTestAdapter)
da = m.NewDownloadAdapter("test")
2016-05-31 10:04:17 +00:00
if assert.NotNil(da) {
assert.Equal("RENAMED", da.Name())
assert.Equal(Download, da.Direction())
}
}
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
func TestAdapterRegButBasicOnly(t *testing.T) {
cli, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
2017-01-04 16:05:29 +00:00
"lfs.basictransfersonly": "yes",
}))
require.Nil(t, err)
2017-10-25 17:46:37 +00:00
m := NewManifest(nil, cli, "", "")
assert := assert.New(t)
m.RegisterNewAdapterFunc("test", Upload, newTestAdapter)
m.RegisterNewAdapterFunc("test", Download, newTestAdapter)
// Will still be created if we ask for them
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
da := m.NewDownloadAdapter("test")
if assert.NotNil(da) {
assert.Equal("test", da.Name())
assert.Equal(Download, da.Direction())
}
ua := m.NewUploadAdapter("test")
if assert.NotNil(ua) {
assert.Equal("test", ua.Name())
assert.Equal(Upload, ua.Direction())
}
// But list will exclude
ld := m.GetDownloadAdapterNames()
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
assert.Equal([]string{"basic"}, ld)
lu := m.GetUploadAdapterNames()
tq/transfer_test.go: enable and fix all tests The three test functions in the tq/transfer_test.go source file are all named with the prefix "test" rather than "Test", and as a result, do not actually execute. This oversight dates from the original introduction of these tests in the "transfer" package in commit 10623f5d7a7d785fb3863c2b190b0f2f99686b7c of PR #1265. (The package was later renamed to the current "tq" package in commit 891db97a429405f80d54c7e09219bda9799e8e6e of PR #1780.) We therefore change the test function names to begin with "Test", and resolve several test regressions which have accumulated since the tests were first added. First, the TestBasicAdapterExists() function calls the GetDownloadAdapterNames() and GetUploadAdapterNames() methods of the Manifest structure, and these now return the names of three transfer adapter implementations rather than just the original "basic" one, so we allow for all three names to appear in any order. (The "lfs-standalone-file" adapter was added in commit bb05cf5053d9abd6d7ca68354ca9663e57bb6737 of PR #3748, and the "ssh" adapter was added in commit 594f8e386cce3441e06c9094ab5e251f0e07ca1f of PR #4446.) Second, the TestAdapterRegAndOverride() function expects the NewDownloadAdapter() and NewUploadAdapter() methods of the Manifest structure to return nil if the provided name argument does not match that of any registered transfer adapter. However, this has not been the behaviour of those methods since commit c5c2a756c70b2a961cea284fc7b00d2753bfaa3b of PR #1279, shortly after the tests were first introduced in PR #1265. In that commit, the NewAdapterOrDefault() method was added, and the NewDownloadAdapter() and NewUploadAdapter() methods revised to call it, so they return the default "basic" adapter if the requested name does not match a registered adapter. We therefore revise and expand the test to account for this behaviour, and also make sure to directly test the underlying NewAdapter() method, which retains the originally intended behaviour and returns nil if it does not find a matching adapter for the provided name argument. Third, although the TestAdapterRegButBasicOnly() function passes without changes, it no longer fully performs the checks it was intended to make, since the NewDownloadAdapter() and NewUploadAdapter() methods now always return a non-nil value, so using a non-nil response from them to prove that the "test" adapter was found is insufficient. We therefore update the test to confirm that the returned value from these functions is a "test" adapter, as expected, and not just a "basic" one. We also replace the use of the BasicAdapterName variable with the "basic" string to align with the other tests.
2023-07-27 00:20:23 +00:00
assert.Equal([]string{"basic"}, lu)
}