summaryrefslogtreecommitdiffstats
path: root/k8s/tests
diff options
context:
space:
mode:
authorJack Lucas <jflucas@research.att.com>2018-07-31 21:10:25 +0000
committerJack Lucas <jflucas@research.att.com>2018-08-01 21:14:45 +0000
commitb13a6e53197bb01a857442680faa78938f1b614e (patch)
tree328e7964fd2e6a597ba6e127fc51eff16b6e09d6 /k8s/tests
parenta2aefd40115798e4093bc2d9e606ad5a34d3e017 (diff)
Fix k8splugin to accept intervals as strings
Also update type file to point to new plugin version Add unit tests for parsing interval Change RE to be non-Python specific Use uppercase for RE constant and unit conversion factors Issue-ID: DCAEGEN2-649 Change-Id: I1de728b3efd0725d4a3da996d95ec61e68f56ab4 Signed-off-by: Jack Lucas <jflucas@research.att.com>
Diffstat (limited to 'k8s/tests')
-rw-r--r--k8s/tests/test_k8sclient.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/k8s/tests/test_k8sclient.py b/k8s/tests/test_k8sclient.py
new file mode 100644
index 0000000..00ccfdb
--- /dev/null
+++ b/k8s/tests/test_k8sclient.py
@@ -0,0 +1,86 @@
+# ============LICENSE_START=======================================================
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
+import pytest
+
+def test_parse_interval():
+ from k8sclient.k8sclient import _parse_interval
+
+ good_intervals = [{"in": input, "ex": expected}
+ for (input, expected) in [
+ (30, 30),
+ ("30", 30),
+ ("30s", 30),
+ ("2m", 2 * 60),
+ ("2h", 2 * 60 * 60),
+ ("24h", 24 * 60 * 60),
+ (354123, 354123),
+ ("354123", 354123),
+ ("354123s", 354123),
+ (1234567890123456789012345678901234567890L,1234567890123456789012345678901234567890L),
+ ("1234567890123456789012345678901234567890",1234567890123456789012345678901234567890L),
+ ("1234567890123456789012345678901234567890s",1234567890123456789012345678901234567890L),
+ ("05s", 5),
+ ("00000000000000000000000000000000005m", 5 * 60)
+ ]
+ ]
+
+ bad_intervals = [
+ -99,
+ "-99",
+ "-99s",
+ "-99m",
+ "-99h",
+ "30d",
+ "30w",
+ "30y",
+ "3 0s",
+ "3 5m",
+ 30.0,
+ "30.0s",
+ "30.0m",
+ "30.0h",
+ "a 30s",
+ "30s a",
+ "a 30s a",
+ "a 30",
+ "30 a",
+ "a 30 a",
+ "i want an interval of 30s",
+ "thirty seconds",
+ "30 s",
+ "30 m",
+ "30 h",
+ 10E0,
+ "10E0",
+ 3.14159,
+ "3.14159s"
+ "3:05",
+ "3m05s",
+ "3seconds",
+ "3S",
+ "1minute",
+ "1stanbul"
+ ]
+
+ for test_case in good_intervals:
+ assert _parse_interval(test_case["in"]) == test_case["ex"]
+
+ for interval in bad_intervals:
+ with pytest.raises(ValueError):
+ _parse_interval(interval) \ No newline at end of file