mirror of https://github.com/apache/cloudstack.git
Refactoring swift util test (#8099)
This commit is contained in:
parent
be039a1e46
commit
91a570e461
|
|
@ -99,12 +99,7 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testGetSwiftCmd() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn(null);
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg(null);
|
||||
|
||||
String cmd = SwiftUtil.getSwiftCmd(cfg, "swift", "stat");
|
||||
|
||||
|
|
@ -114,12 +109,7 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testGetSwiftObjectCmd() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn(null);
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg(null);
|
||||
|
||||
String objectCmd = SwiftUtil.getSwiftObjectCmd(cfg, "swift", "delete", "T-123", "template.vhd");
|
||||
|
||||
|
|
@ -129,12 +119,7 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testGetSwiftContainerCmd() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn(null);
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg(null);
|
||||
|
||||
String containerCmd = SwiftUtil.getSwiftContainerCmd(cfg, "swift", "list", "T-123");
|
||||
|
||||
|
|
@ -144,27 +129,16 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testGetUploadCmd() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn(null);
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg(null);
|
||||
|
||||
String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 1024);
|
||||
|
||||
String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword upload T-1 template.vhd";
|
||||
assertThat(uploadCmd, is(equalTo(expected)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploadCmdWithSegmentsBecauseOfSize() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn(null);
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg(null);
|
||||
|
||||
String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 5368709121L);
|
||||
|
||||
|
|
@ -174,12 +148,7 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testGetUploadCmdWithStoragePolicy() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn("policy1");
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg("policy1");
|
||||
|
||||
String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 1024L);
|
||||
String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword upload T-1 template.vhd --storage-policy \"policy1\"";
|
||||
|
|
@ -188,12 +157,7 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testGetUploadCmdWithSegmentsAndStoragePolicy() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn("policy1");
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg("policy1");
|
||||
String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 5368709121L);
|
||||
String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword upload T-1 template.vhd --storage-policy \"policy1\" -S 5368709120";
|
||||
assertThat(uploadCmd, is(equalTo(expected)));
|
||||
|
|
@ -201,12 +165,7 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testListContainerCmdWithStoragePolicyButNotSupportedByOperation() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn("policy1");
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg("policy1");
|
||||
|
||||
String uploadCmd = SwiftUtil.getSwiftContainerCmd(cfg, "swift", "list", "T-1");
|
||||
String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword list T-1";
|
||||
|
|
@ -215,15 +174,20 @@ public class SwiftUtilTest {
|
|||
|
||||
@Test
|
||||
public void testListContainerCmdWithoutStoragePolicy() {
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn(null);
|
||||
SwiftClientCfg cfg = CreateMockSwiftClientCfg(null);
|
||||
|
||||
String uploadCmd = SwiftUtil.getSwiftContainerCmd(cfg, "swift", "list", "T-1");
|
||||
String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword list T-1";
|
||||
assertThat(uploadCmd, is(equalTo(expected)));
|
||||
}
|
||||
|
||||
private SwiftClientCfg CreateMockSwiftClientCfg(String policy){
|
||||
SwiftClientCfg cfg = mock(SwiftClientCfg.class);
|
||||
given(cfg.getEndPoint()).willReturn("swift.endpoint");
|
||||
given(cfg.getAccount()).willReturn("cs");
|
||||
given(cfg.getUserName()).willReturn("sec-storage");
|
||||
given(cfg.getKey()).willReturn("mypassword");
|
||||
given(cfg.getStoragePolicy()).willReturn(policy);
|
||||
return cfg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue