K8sVersion { public boolean newerOrEqualThan(int major, int minor) { try { initVersionInfo(); } catch (InfrastructureException ie) { LOG.warn("Unable to obtain k8s VersionInfo.", ie); return true; } if (this.major > major) { return true; } else if (this.major == major) { return this.minor >= minor; } else { return false; } } @Inject  K8sVersion(KubernetesClientFactory clientFactory); boolean newerOrEqualThan(int major, int minor); boolean olderThan(int major, int minor);  }
@Test(dataProvider = "greaterThanData") public void testGreaterOrEqual(VersionInfo versionInfo, int major, int minor, boolean expected) { when(kubernetesClient.getVersion()).thenReturn(versionInfo); assertEquals(k8sVersion.newerOrEqualThan(major, minor), expected); }
@Test public void testGreaterOrEqualTrueWhenInfrastructureFails() throws InfrastructureException { when(kubernetesClientFactory.create()).thenThrow(new InfrastructureException("eh")); assertTrue(k8sVersion.newerOrEqualThan(1, 1)); assertTrue(k8sVersion.newerOrEqualThan(-1, -1)); assertTrue(k8sVersion.newerOrEqualThan(0, 1)); assertTrue(k8sVersion.newerOrEqualThan(0, 0)); assertTrue(k8sVersion.newerOrEqualThan(1337, 1337)); assertTrue(k8sVersion.newerOrEqualThan(6655321, 6655321)); }
@Test public void testGreaterOrEqualWhenParseFailure() throws ParseException { when(kubernetesClient.getVersion()).thenReturn(createDummyVersionInfo("abc", "cde")); assertTrue(k8sVersion.newerOrEqualThan(1, 1)); assertTrue(k8sVersion.newerOrEqualThan(-1, -1)); assertTrue(k8sVersion.newerOrEqualThan(0, 1)); assertTrue(k8sVersion.newerOrEqualThan(0, 0)); assertTrue(k8sVersion.newerOrEqualThan(1337, 1337)); assertTrue(k8sVersion.newerOrEqualThan(6655321, 6655321)); }