You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2023/10/18 08:00:58 UTC
[cloudstack] branch main updated: Refactoring swift util test (#8099)
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 91a570e4619 Refactoring swift util test (#8099)
91a570e4619 is described below
commit 91a570e4619be2ac452412363047d4c0c1b74711
Author: gzhao9 <74...@users.noreply.github.com>
AuthorDate: Wed Oct 18 04:00:52 2023 -0400
Refactoring swift util test (#8099)
---
.../test/java/com/cloud/utils/SwiftUtilTest.java | 72 ++++++----------------
1 file changed, 18 insertions(+), 54 deletions(-)
diff --git a/utils/src/test/java/com/cloud/utils/SwiftUtilTest.java b/utils/src/test/java/com/cloud/utils/SwiftUtilTest.java
index 6dc2cc78cac..d5176839c76 100644
--- a/utils/src/test/java/com/cloud/utils/SwiftUtilTest.java
+++ b/utils/src/test/java/com/cloud/utils/SwiftUtilTest.java
@@ -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 = 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(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)));
+ given(cfg.getStoragePolicy()).willReturn(policy);
+ return cfg;
}
}