Test: List files in OneDrive

pull/348/head
HFO4 5 years ago
parent 8a2be58ef3
commit 79daf92896

@ -1 +1 @@
Subproject commit d752e266d52230b3334b88b22facd9f5d37eda9e
Subproject commit 1b9186c3c7aab6a619fc7e872ada9f65ca08a34a

@ -752,6 +752,66 @@ func TestClient_Delete(t *testing.T) {
}
}
func TestClient_ListChildren(t *testing.T) {
asserts := assert.New(t)
client, _ := NewClient(&model.Policy{})
client.Credential.AccessToken = "AccessToken"
// 根目录,请求失败,重测试
{
client.Credential.ExpiresIn = 0
res, err := client.ListChildren(context.Background(), "/")
asserts.Error(err)
asserts.Empty(res)
}
// 非根目录,未知响应
{
client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
clientMock := ClientMock{}
clientMock.On(
"Request",
"GET",
testMock.Anything,
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`???`)),
},
})
client.Request = clientMock
res, err := client.ListChildren(context.Background(), "/uploads")
asserts.Error(err)
asserts.Empty(res)
}
// 非根目录,成功
{
client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
clientMock := ClientMock{}
clientMock.On(
"Request",
"GET",
testMock.Anything,
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"value":[{}]}`)),
},
})
client.Request = clientMock
res, err := client.ListChildren(context.Background(), "/uploads")
asserts.NoError(err)
asserts.Len(res, 1)
}
}
func TestClient_GetThumbURL(t *testing.T) {
asserts := assert.New(t)
client, _ := NewClient(&model.Policy{})

@ -174,6 +174,78 @@ func TestDriver_Source(t *testing.T) {
}
}
func TestDriver_List(t *testing.T) {
asserts := assert.New(t)
handler := Driver{
Policy: &model.Policy{
AccessKey: "ak",
SecretKey: "sk",
BucketName: "test",
Server: "test.com",
},
}
handler.Client, _ = NewClient(&model.Policy{})
handler.Client.Credential.AccessToken = "AccessToken"
handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
// 非递归
{
clientMock := ClientMock{}
clientMock.On(
"Request",
"GET",
testMock.Anything,
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"value":[{}]}`)),
},
})
handler.Client.Request = clientMock
res, err := handler.List(context.Background(), "/", false)
asserts.NoError(err)
asserts.Len(res, 1)
}
// 递归一次
{
clientMock := ClientMock{}
clientMock.On(
"Request",
"GET",
"me/drive/root/children?$top=999999999",
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"value":[{"name":"1","folder":{}}]}`)),
},
})
clientMock.On(
"Request",
"GET",
"me/drive/root:/1:/children?$top=999999999",
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"value":[{"name":"2"}]}`)),
},
})
handler.Client.Request = clientMock
res, err := handler.List(context.Background(), "/", true)
asserts.NoError(err)
asserts.Len(res, 2)
}
}
func TestDriver_Thumb(t *testing.T) {
asserts := assert.New(t)
handler := Driver{

Loading…
Cancel
Save