2017-07-25 16:18:13 +02:00
|
|
|
// Test AzureBlob filesystem interface
|
2018-07-13 17:21:49 +02:00
|
|
|
|
2021-09-09 14:25:25 +02:00
|
|
|
//go:build !plan9 && !solaris && !js
|
2021-08-20 19:05:14 +02:00
|
|
|
// +build !plan9,!solaris,!js
|
2018-07-13 17:21:49 +02:00
|
|
|
|
2018-09-07 13:02:27 +02:00
|
|
|
package azureblob
|
2017-07-25 16:18:13 +02:00
|
|
|
|
|
|
|
import (
|
2020-12-06 06:13:51 +01:00
|
|
|
"context"
|
2017-07-25 16:18:13 +02:00
|
|
|
"testing"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fstest/fstests"
|
2020-12-06 06:13:51 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-07-25 16:18:13 +02:00
|
|
|
)
|
|
|
|
|
2018-04-07 19:48:11 +02:00
|
|
|
// TestIntegration runs integration tests against the remote
|
|
|
|
func TestIntegration(t *testing.T) {
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
2021-11-12 13:12:20 +01:00
|
|
|
RemoteName: "TestAzureBlob:",
|
|
|
|
NilObject: (*Object)(nil),
|
|
|
|
TiersToTest: []string{"Hot", "Cool"},
|
|
|
|
ChunkedUpload: fstests.ChunkedUploadConfig{},
|
2018-04-07 19:48:11 +02:00
|
|
|
})
|
2017-07-25 16:18:13 +02:00
|
|
|
}
|
2018-09-07 13:02:27 +02:00
|
|
|
|
|
|
|
func (f *Fs) SetUploadChunkSize(cs fs.SizeSuffix) (fs.SizeSuffix, error) {
|
|
|
|
return f.setUploadChunkSize(cs)
|
|
|
|
}
|
|
|
|
|
2018-10-13 23:45:17 +02:00
|
|
|
var (
|
|
|
|
_ fstests.SetUploadChunkSizer = (*Fs)(nil)
|
|
|
|
)
|
2020-12-06 06:13:51 +01: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")
|
|
|
|
}
|
2022-05-21 20:36:18 +02:00
|
|
|
|
|
|
|
func TestValidateAccessTier(t *testing.T) {
|
|
|
|
tests := map[string]struct {
|
|
|
|
accessTier string
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
"hot": {"hot", true},
|
|
|
|
"HOT": {"HOT", true},
|
|
|
|
"Hot": {"Hot", true},
|
|
|
|
"cool": {"cool", true},
|
|
|
|
"archive": {"archive", true},
|
|
|
|
"empty": {"", false},
|
|
|
|
"unknown": {"unknown", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, test := range tests {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
got := validateAccessTier(test.accessTier)
|
|
|
|
assert.Equal(t, test.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|