2017-07-25 22:18:13 +08:00
|
|
|
// Test AzureBlob filesystem interface
|
2018-07-13 23:21:49 +08:00
|
|
|
|
2021-08-21 01:05:14 +08:00
|
|
|
// +build !plan9,!solaris,!js
|
2018-07-13 23:21:49 +08:00
|
|
|
|
2018-09-07 19:02:27 +08:00
|
|
|
package azureblob
|
2017-07-25 22:18:13 +08:00
|
|
|
|
|
|
|
import (
|
2020-12-06 13:13:51 +08:00
|
|
|
"context"
|
2017-07-25 22:18:13 +08:00
|
|
|
"testing"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fstest/fstests"
|
2020-12-06 13:13:51 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-07-25 22:18:13 +08:00
|
|
|
)
|
|
|
|
|
2018-04-08 01:48:11 +08:00
|
|
|
// TestIntegration runs integration tests against the remote
|
|
|
|
func TestIntegration(t *testing.T) {
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
2018-09-18 20:25:20 +08:00
|
|
|
RemoteName: "TestAzureBlob:",
|
2018-09-07 19:02:27 +08:00
|
|
|
NilObject: (*Object)(nil),
|
2018-09-18 20:25:20 +08:00
|
|
|
TiersToTest: []string{"Hot", "Cool"},
|
2018-09-07 19:02:27 +08:00
|
|
|
ChunkedUpload: fstests.ChunkedUploadConfig{
|
|
|
|
MaxChunkSize: maxChunkSize,
|
|
|
|
},
|
2018-04-08 01:48:11 +08:00
|
|
|
})
|
2017-07-25 22:18:13 +08:00
|
|
|
}
|
2018-09-07 19:02:27 +08:00
|
|
|
|
|
|
|
func (f *Fs) SetUploadChunkSize(cs fs.SizeSuffix) (fs.SizeSuffix, error) {
|
|
|
|
return f.setUploadChunkSize(cs)
|
|
|
|
}
|
|
|
|
|
2018-10-14 05:45:17 +08:00
|
|
|
var (
|
|
|
|
_ fstests.SetUploadChunkSizer = (*Fs)(nil)
|
|
|
|
)
|
2020-12-06 13:13:51 +08:00
|
|
|
|
|
|
|
// TestServicePrincipalFileSuccess checks that, given a proper JSON file, we can create a token.
|
|
|
|
func TestServicePrincipalFileSuccess(t *testing.T) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
credentials := `
|
|
|
|
{
|
|
|
|
"appId": "my application (client) ID",
|
|
|
|
"password": "my secret",
|
|
|
|
"tenant": "my active directory tenant ID"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
tokenRefresher, err := newServicePrincipalTokenRefresher(ctx, []byte(credentials))
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.NotNil(t, tokenRefresher)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestServicePrincipalFileFailure checks that, given a JSON file with a missing secret, it returns an error.
|
|
|
|
func TestServicePrincipalFileFailure(t *testing.T) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
credentials := `
|
|
|
|
{
|
|
|
|
"appId": "my application (client) ID",
|
|
|
|
"tenant": "my active directory tenant ID"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
_, err := newServicePrincipalTokenRefresher(ctx, []byte(credentials))
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.EqualError(t, err, "error creating service principal token: parameter 'secret' cannot be empty")
|
|
|
|
}
|