提交 960c8864 编写于 作者: H HFO4

Test: slave side list file

上级 5d579cda
......@@ -223,6 +223,89 @@ func TestHandler_Delete(t *testing.T) {
}
}
func TestDriver_List(t *testing.T) {
asserts := assert.New(t)
handler := Driver{
Policy: &model.Policy{
SecretKey: "test",
Server: "http://test.com",
},
AuthInstance: auth.HMACAuth{},
}
ctx := context.Background()
cache.Set("setting_slave_api_timeout", "60", 0)
// 成功
{
clientMock := ClientMock{}
clientMock.On(
"Request",
"POST",
"http://test.com/api/v3/slave/list",
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"code":0,"data":"[{}]"}`)),
},
})
handler.Client = clientMock
res, err := handler.List(ctx, "/", true)
clientMock.AssertExpectations(t)
asserts.NoError(err)
asserts.Len(res, 1)
}
// 响应解析失败
{
clientMock := ClientMock{}
clientMock.On(
"Request",
"POST",
"http://test.com/api/v3/slave/list",
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"code":0,"data":"233"}`)),
},
})
handler.Client = clientMock
res, err := handler.List(ctx, "/", true)
clientMock.AssertExpectations(t)
asserts.Error(err)
asserts.Len(res, 0)
}
// 从机返回错误
{
clientMock := ClientMock{}
clientMock.On(
"Request",
"POST",
"http://test.com/api/v3/slave/list",
testMock.Anything,
testMock.Anything,
).Return(&request.Response{
Err: nil,
Response: &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader(`{"code":203}`)),
},
})
handler.Client = clientMock
res, err := handler.List(ctx, "/", true)
clientMock.AssertExpectations(t)
asserts.Error(err)
asserts.Len(res, 0)
}
}
func TestHandler_Get(t *testing.T) {
asserts := assert.New(t)
handler := Driver{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册