forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fabric8io#2107: Set PropagationPolicy to Background by default
- Loading branch information
1 parent
791fbac
commit 9a4aefe
Showing
51 changed files
with
681 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
extensions/knative/tests/src/test/java/io/fabric8/knative/test/ServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.knative.test; | ||
|
||
import io.fabric8.knative.client.KnativeClient; | ||
import io.fabric8.knative.mock.KnativeServer; | ||
import io.fabric8.knative.serving.v1.Service; | ||
import io.fabric8.knative.serving.v1.ServiceBuilder; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@EnableRuleMigrationSupport | ||
public class ServiceTest { | ||
@Rule | ||
public KnativeServer server = new KnativeServer(); | ||
|
||
@Test | ||
@DisplayName("Should get a Knative Service") | ||
public void testGet() { | ||
Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().build(); | ||
server.expect().get().withPath("/apis/serving.knative.dev/v1/namespaces/ns2/services/service2") | ||
.andReturn(HttpURLConnection.HTTP_OK, service2) | ||
.once(); | ||
KnativeClient client = server.getKnativeClient(); | ||
|
||
Service service = client.services().inNamespace("ns2").withName("service2").get(); | ||
assertNotNull(service); | ||
assertEquals("service2", service.getMetadata().getName()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should Create a Knative Service") | ||
public void testCreate() { | ||
Service service = new ServiceBuilder().withNewMetadata().withName("service").endMetadata().build(); | ||
server.expect().post().withPath("/apis/serving.knative.dev/v1/namespaces/ns2/services") | ||
.andReturn(HttpURLConnection.HTTP_OK, service) | ||
.once(); | ||
KnativeClient client = server.getKnativeClient(); | ||
service = client.services().inNamespace("ns2").create(service); | ||
assertNotNull(service); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should Delete a Knative Service") | ||
public void testDelete() throws InterruptedException { | ||
server.expect().delete().withPath("/apis/serving.knative.dev/v1/namespaces/ns3/services/service3") | ||
.andReturn(HttpURLConnection.HTTP_OK, new ServiceBuilder().build()) | ||
.once(); | ||
KnativeClient client = server.getKnativeClient(); | ||
Boolean deleted = client.services().inNamespace("ns3").withName("service3").delete(); | ||
assertTrue(deleted); | ||
|
||
RecordedRequest recordedRequest = server.getMockServer().takeRequest(); | ||
assertEquals("{\"apiVersion\":\"v1\",\"kind\":\"DeleteOptions\",\"propagationPolicy\":\"Background\"}", recordedRequest.getBody().readUtf8()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should delete with PropagationPolicy=Orphan") | ||
public void testDeleteOrphan() throws InterruptedException { | ||
server.expect().delete().withPath("/apis/serving.knative.dev/v1/namespaces/ns3/services/service3") | ||
.andReturn(HttpURLConnection.HTTP_OK, new ServiceBuilder().build()) | ||
.once(); | ||
KnativeClient client = server.getKnativeClient(); | ||
Boolean deleted = client.services().inNamespace("ns3").withName("service3").withPropagationPolicy("Orphan").delete(); | ||
assertTrue(deleted); | ||
|
||
RecordedRequest recordedRequest = server.getMockServer().takeRequest(); | ||
assertEquals("{\"apiVersion\":\"v1\",\"kind\":\"DeleteOptions\",\"propagationPolicy\":\"Orphan\"}", recordedRequest.getBody().readUtf8()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/PipelineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.tekton.pipeline.v1beta1; | ||
|
||
import io.fabric8.tekton.client.TektonClient; | ||
import io.fabric8.tekton.mock.TektonServer; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@EnableRuleMigrationSupport | ||
public class PipelineTest { | ||
@Rule | ||
public TektonServer server = new TektonServer(); | ||
|
||
@Test | ||
@DisplayName("Should get a pipeline") | ||
public void testGet() { | ||
server.expect().get().withPath("/apis/tekton.dev/v1beta1/namespaces/ns1/pipelines/pipeline") | ||
.andReturn(HttpURLConnection.HTTP_OK, new io.fabric8.tekton.pipeline.v1beta1.PipelineBuilder() | ||
.withNewMetadata() | ||
.withName("pipeline") | ||
.endMetadata() | ||
.build()).once(); | ||
TektonClient client = server.getTektonClient(); | ||
|
||
Pipeline pipeline = client.v1beta1().pipelines().inNamespace("ns1").withName("pipeline").get(); | ||
assertNotNull(pipeline); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should create a pipeline") | ||
public void testCreate() { | ||
Pipeline pipeline = new io.fabric8.tekton.pipeline.v1beta1.PipelineBuilder().withNewMetadata().withName("pipeline").endMetadata().build(); | ||
server.expect().post().withPath("/apis/tekton.dev/v1beta1/namespaces/ns1/pipelines") | ||
.andReturn(HttpURLConnection.HTTP_OK, pipeline).once(); | ||
TektonClient client = server.getTektonClient(); | ||
|
||
pipeline = client.v1beta1().pipelines().inNamespace("ns1").create(pipeline); | ||
assertNotNull(pipeline); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should delete a pipeline") | ||
public void testDelete() throws InterruptedException { | ||
server.expect().delete().withPath("/apis/tekton.dev/v1beta1/namespaces/ns1/pipelines/pipeline") | ||
.andReturn(HttpURLConnection.HTTP_OK, new io.fabric8.tekton.pipeline.v1beta1.PipelineBuilder().build()) | ||
.once(); | ||
TektonClient client = server.getTektonClient(); | ||
|
||
Boolean isDeleted = client.v1beta1().pipelines().inNamespace("ns1").withName("pipeline").delete(); | ||
assertTrue(isDeleted); | ||
|
||
RecordedRequest recordedRequest = server.getMockServer().takeRequest(); | ||
assertEquals("{\"apiVersion\":\"v1\",\"kind\":\"DeleteOptions\",\"propagationPolicy\":\"Background\"}", recordedRequest.getBody().readUtf8()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should delete pipeline with some explicit propagationpolicy") | ||
public void testDeleteOrphan() throws InterruptedException { | ||
server.expect().delete().withPath("/apis/tekton.dev/v1beta1/namespaces/ns1/pipelines/pipeline") | ||
.andReturn(HttpURLConnection.HTTP_OK, new io.fabric8.tekton.pipeline.v1beta1.PipelineBuilder().build()) | ||
.once(); | ||
TektonClient client = server.getTektonClient(); | ||
|
||
Boolean isDeleted = client.v1beta1().pipelines().inNamespace("ns1").withName("pipeline").withPropagationPolicy("Orphan").delete(); | ||
assertTrue(isDeleted); | ||
|
||
RecordedRequest recordedRequest = server.getMockServer().takeRequest(); | ||
assertEquals("{\"apiVersion\":\"v1\",\"kind\":\"DeleteOptions\",\"propagationPolicy\":\"Orphan\"}", recordedRequest.getBody().readUtf8()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.