Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #324 - Migrate e2e tests to bddframework #356

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bddframework/pkg/framework/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -96,6 +95,9 @@ func WaitForFailedHTTPRequest(namespace string, requestInfo HTTPRequestInfo, tim
})
}

// TODO: implement a ExecuteHTTPRequest using a curl image, so we can query the services from within the cluster
// TODO: kubectl run -n $NS -it --rm --image=curlimages/curl curly -- http://10.96.83.64

// ExecuteHTTPRequest executes an HTTP request
func ExecuteHTTPRequest(namespace string, requestInfo HTTPRequestInfo) (*http.Response, error) {
// Setup a retry in case the first time it did not work
Expand Down Expand Up @@ -217,7 +219,7 @@ func checkHTTPRequestConditionC(client *http.Client, namespace string, requestIn
if err != nil {
return false, err
}
if _, err = io.Copy(ioutil.Discard, response.Body); err != nil { // Just read the response to be able to close the connection properly
if _, err = io.Copy(io.Discard, response.Body); err != nil { // Just read the response to be able to close the connection properly
return false, err
}
defer response.Body.Close()
Expand Down Expand Up @@ -282,7 +284,7 @@ func createDefaultClient() *http.Client {
customTransport := defaultTransport.Clone()
// Allow executing requests against HTTPS endpoints with insecure certificate
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
return &http.Client{Transport: customTransport, Timeout: (time.Duration(10*config.GetLoadFactor()) * time.Second)}
return &http.Client{Transport: customTransport, Timeout: time.Duration(10*config.GetLoadFactor()) * time.Second}
}

func runRequestRoutine(threadID int, waitGroup *sync.WaitGroup, client *http.Client, namespace string, requestPerThread int, requestInfo HTTPRequestInfo, results []HTTPRequestResult) {
Expand All @@ -303,7 +305,7 @@ func runRequestRoutine(threadID int, waitGroup *sync.WaitGroup, client *http.Cli
results[threadID] = HTTPRequestResultSuccess
}

// IsHTTPResponseArraySize makes and checks whether an http request returns an array of a specific size
// IsHTTPResponseArraySize makes and checks whether a http request returns an array of a specific size
func IsHTTPResponseArraySize(namespace string, requestInfo HTTPRequestInfo, arraySize int) (bool, error) {
var httpResponseArray []map[string]interface{}
err := ExecuteHTTPRequestWithUnmarshalledResponse(namespace, requestInfo, &httpResponseArray)
Expand Down
4 changes: 2 additions & 2 deletions controllers/profiles/dev/profile_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ func newObjectEnsurersOpenShift(support *common.StateSupport) *objectEnsurers {

func newStatusEnrichers(support *common.StateSupport) *statusEnrichers {
return &statusEnrichers{
networkInfo: common.NewStatusEnricher(support.C, statusEnricher),
networkInfo: common.NewStatusEnricher(support.C, workflowAddressableStatusEnricher),
}
}

func newStatusEnrichersOpenShift(support *common.StateSupport) *statusEnrichers {
return &statusEnrichers{
networkInfo: common.NewStatusEnricher(support.C, statusEnricherOpenShift),
networkInfo: common.NewStatusEnricher(support.C, workflowAddressableStatusEnricherOpenShift),
}
}

Expand Down
10 changes: 6 additions & 4 deletions controllers/profiles/dev/status_enricher_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
)

func statusEnricher(ctx context.Context, c client.Client, workflow *operatorapi.SonataFlow) (client.Object, error) {
//If the workflow Status hasn't got a NodePort Endpoint, we are ensuring it will be set
func workflowAddressableStatusEnricher(ctx context.Context, c client.Client, workflow *operatorapi.SonataFlow) (client.Object, error) {
// If the workflow Status hasn't got a NodePort Endpoint, statusEnricherwe are ensuring it will be set
// If we aren't on OpenShift we will enrich the status with 2 info:
// - Address the service can be reached
// - Node port used
Expand All @@ -49,6 +49,8 @@ func statusEnricher(ctx context.Context, c client.Client, workflow *operatorapi.

//If the service has got a Port that is a nodePort we have to use it to create the workflow's NodePort Endpoint
if service.Spec.Ports != nil && len(service.Spec.Ports) > 0 {
// TODO: Replace with LoadBalancer option https://minikube.sigs.k8s.io/docs/handbook/accessing/#using-minikube-tunnel
// TODO: remove Endpoint, use only URL
if port := findNodePortFromPorts(service.Spec.Ports); port > 0 {
labels := workflowproj.GetDefaultLabels(workflow)

Expand All @@ -74,7 +76,7 @@ func statusEnricher(ctx context.Context, c client.Client, workflow *operatorapi.
workflow.Status.Endpoint = url
}

address, err := kubernetes.RetrieveServiceURL(service)
address, err := kubernetes.RetrieveWorkflowServiceURL(service)
if err != nil {
return nil, err
}
Expand All @@ -99,7 +101,7 @@ func findNodePortFromPorts(ports []v1.ServicePort) int {
return 0
}

func statusEnricherOpenShift(ctx context.Context, client client.Client, workflow *operatorapi.SonataFlow) (client.Object, error) {
func workflowAddressableStatusEnricherOpenShift(ctx context.Context, client client.Client, workflow *operatorapi.SonataFlow) (client.Object, error) {
// On OpenShift we need to retrieve the Route to have the URL the service is available to
route := &openshiftv1.Route{}
err := client.Get(ctx, types.NamespacedName{Namespace: workflow.Namespace, Name: workflow.Name}, route)
Expand Down
6 changes: 3 additions & 3 deletions controllers/profiles/dev/status_enricher_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Test_enrichmentStatusOnK8s(t *testing.T) {
workflow.Namespace = toK8SNamespace(t.Name())
service, _ := common.ServiceCreator(workflow)
client := test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, service).Build()
obj, err := statusEnricher(context.TODO(), client, workflow)
obj, err := workflowAddressableStatusEnricher(context.TODO(), client, workflow)

reflectWorkflow := obj.(*apiv08.SonataFlow)
assert.NoError(t, err)
Expand All @@ -57,7 +57,7 @@ func Test_enrichmentStatusOnK8s(t *testing.T) {
workflow.Namespace = t.Name()
service, _ := serviceCreator(workflow)
client := test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, service).Build()
_, err := statusEnricher(context.TODO(), client, workflow)
_, err := workflowAddressableStatusEnricher(context.TODO(), client, workflow)
assert.Error(t, err)

})
Expand All @@ -73,7 +73,7 @@ func Test_enrichmentStatusOnOCP(t *testing.T) {
route.Namespace = workflow.Namespace
route.Spec.Host = workflow.Name + "." + workflow.Namespace + ".apps-crc.testing"
client := test.NewKogitoClientBuilderWithOpenShift().WithRuntimeObjects(workflow, service, route).Build()
obj, err := statusEnricherOpenShift(context.TODO(), client, workflow)
obj, err := workflowAddressableStatusEnricherOpenShift(context.TODO(), client, workflow)

reflectWorkflow := obj.(*apiv08.SonataFlow)
assert.NoError(t, err)
Expand Down
Loading