Skip to content

Commit

Permalink
Merge pull request #3 from rh-messaging/nb-travis-ci-hello-world
Browse files Browse the repository at this point in the history
Initial travis-ci for qdr-shipshape repo
  • Loading branch information
nicob87 authored Mar 5, 2020
2 parents 0e205c8 + 983bfda commit 20c90fe
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
sudo: required
dist: bionic
language: go
go:
- master

go_import_path: github.com/rh-messaging/qdr-shipshape

services:
- docker

git:
depth: 1

env:
global:
- KUBECONFIG=$HOME/.kube/config
- KUBERNETES_VERSION=$(curl -k -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
- GO111MODULE=on

before_install:
# Setup kubectl
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/linux/amd64/kubectl
- chmod +x kubectl
- sudo mv kubectl /usr/local/bin/

# Get tools
- env GO111MODULE=off go get sigs.k8s.io/kind
- env GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo

# Create a new Kubernetes cluster using KinD
- kind create cluster
- kubectl cluster-info


script:
- env GO111MODULE=on make travis-tests
- make unit-tests
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ clients-python:
docker build -t qdrshipshape/clients-python clients/python/
docker tag qdrshipshape/clients-python docker.io/qdrshipshape/clients-python
docker push docker.io/qdrshipshape/clients-python

.PHONY: travis-tests
travis-tests:
ginkgo -v -r ./test/travis
29 changes: 29 additions & 0 deletions pkg/messaging/message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package messaging_test

import (
"github.com/rh-messaging/qdr-shipshape/pkg/messaging"
"testing"
)

const (
message = "Hello_World"
)

func TestGenerateMessageContent(t *testing.T) {
message_len := len(message)
_test := func(t *testing.T, expected string, _len int) {
received := messaging.GenerateMessageContent(message, _len)
if received != expected {
t.Error(
"Expected", expected,
"Got", received,
)
}
}

_test(t, message[0:message_len-1], message_len-1)
_test(t, message, message_len)
_test(t, message+"H", message_len+1)
_test(t, "", 0)
_test(t, "", -1)
}
67 changes: 67 additions & 0 deletions test/travis/send_receive/python_cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package send_receive

import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/rh-messaging/qdr-shipshape/pkg/spec/interconnect"
"github.com/rh-messaging/shipshape/pkg/api/client/amqp"
"github.com/rh-messaging/shipshape/pkg/api/client/amqp/qeclients"
"github.com/rh-messaging/shipshape/pkg/framework/log"
)

const (
MessageCount int = 100
)

var _ = Describe("Exchanges AnyCast messages across the nodes", func() {

It("Exchanges small messages", func() {
var (
pythonSender *qeclients.AmqpQEClientCommon
pythonReceiver *qeclients.AmqpQEClientCommon
err error
)

ctx := travisFramework.GetFirstContext()
base_url := fmt.Sprintf("amqp://%s:5672/", interconnect.GetDefaultServiceName(IcInteriorRouterName, ctx.Namespace))
url := base_url + "anycastAddress"

By("Deploying one Python sender and one Python receiver")

pythonSenderBuilder := qeclients.NewSenderBuilder("sender-"+IcInteriorRouterName, qeclients.Python, *ctx, url)
pythonSenderBuilder.Messages(MessageCount)
pythonSenderBuilder.MessageContentFromFile(ConfigMapName, "small-message.txt")
pythonSender, err = pythonSenderBuilder.Build()
Expect(err).NotTo(HaveOccurred())
Expect(pythonSender).NotTo(BeNil())

pythonReceiverBuilder := qeclients.NewReceiverBuilder("receiver-"+IcInteriorRouterName, qeclients.Python, *ctx, url)
pythonReceiverBuilder.Messages(MessageCount)
pythonReceiver, err = pythonReceiverBuilder.Build()
Expect(err).NotTo(HaveOccurred())
Expect(pythonReceiver).NotTo(BeNil())

err = pythonSender.Deploy()
Expect(err).NotTo(HaveOccurred())

err = pythonReceiver.Deploy()
Expect(err).NotTo(HaveOccurred())

pythonSender.Wait()
Expect(pythonSender.Status()).To(Equal(amqp.Success))

pythonReceiver.Wait()
Expect(pythonReceiver.Status()).To(Equal(amqp.Success))

log.Logf("Sender %s - Results - Delivered: %d - Released: %d - Modified: %d",
pythonSender.Name, pythonSender.Result().Delivered, pythonSender.Result().Released, pythonSender.Result().Modified)

log.Logf("Receiver %s - Results - Delivered: %d - Released: %d - Modified: %d",
pythonReceiver.Name, pythonReceiver.Result().Delivered, pythonReceiver.Result().Released, pythonReceiver.Result().Modified)

Expect(pythonReceiver.Result().Delivered).To(Equal(MessageCount))
Expect(pythonSender.Result().Delivered).To(Equal(MessageCount))

})
})
14 changes: 14 additions & 0 deletions test/travis/send_receive/send_receive_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package send_receive_test

import (
"github.com/rh-messaging/qdr-shipshape/pkg/testcommon"
"testing"
)

func TestMain(m *testing.M) {
testcommon.Initialize(m)
}

func TestInterioredge(t *testing.T) {
testcommon.RunSpecs(t, "travis_send_receive", "travis-ci base test")
}
82 changes: 82 additions & 0 deletions test/travis/send_receive/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package send_receive

import (
"github.com/interconnectedcloud/qdr-operator/pkg/apis/interconnectedcloud/v1alpha1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/rh-messaging/qdr-shipshape/pkg/messaging"
"github.com/rh-messaging/shipshape/pkg/apps/qdrouterd/deployment"
"github.com/rh-messaging/shipshape/pkg/apps/qdrouterd/qdrmanagement"
"github.com/rh-messaging/shipshape/pkg/apps/qdrouterd/qdrmanagement/entities"
"github.com/rh-messaging/shipshape/pkg/framework"
"github.com/rh-messaging/shipshape/pkg/framework/operators"
v1 "k8s.io/api/core/v1"
"time"
)

const (
IcInteriorRouterName = "interior"
ConfigMapName = "messaging-files"
)

var IcInteriorRouterSpec *v1alpha1.InterconnectSpec = &v1alpha1.InterconnectSpec{
DeploymentPlan: v1alpha1.DeploymentPlanType{
Size: 1,
Image: "quay.io/interconnectedcloud/qdrouterd:latest",
Role: "interior",
Placement: "Any",
},
}

var (
travisFramework *framework.Framework
ConfigMap *v1.ConfigMap
)

var _ = BeforeEach(func() {
// Initializes using only Qdr Operator
travisFramework = framework.NewFrameworkBuilder("travis").WithBuilders(operators.SupportedOperators[operators.OperatorTypeQdr]).Build()

messaging.GenerateSmallMediumLargeMessagesConfigMap(travisFramework, ConfigMapName)

deployInterconnect()
By("Validating router created")
time.Sleep(5 * time.Second) //wait for router to start
validateNetwork()
})

func validateNetwork() {
var delayS int = 10
var timeoutS int = 60
ctx := travisFramework.GetFirstContext()

podList, err := ctx.ListPodsForDeploymentName(IcInteriorRouterName)
Expect(err).To(BeNil())
Expect(len(podList.Items)).To(Equal(1))
pod := podList.Items[0]

nodes, err := qdrmanagement.QdmanageQueryWithRetries(*ctx, pod.Name, entities.Node{}, delayS,
timeoutS, nil, func(es []entities.Entity, err error) bool {
return err != nil || len(es) == 1 //what does this mean?
})

Expect(err).To(BeNil())
Expect(len(nodes)).To(Equal(1))
}

func deployInterconnect() {
// Deploying Interconnect using provided context
ctx := travisFramework.GetFirstContext()

ic, err := deployment.CreateInterconnectFromSpec(*ctx, IcInteriorRouterSpec.DeploymentPlan.Size,
IcInteriorRouterName, *IcInteriorRouterSpec)

Expect(err).To(BeNil())
Expect(ic).NotTo(BeNil())

// Wait for Interconnect deployment
err = framework.WaitForDeployment(ctx.Clients.KubeClient, ctx.Namespace,
IcInteriorRouterName, int(IcInteriorRouterSpec.DeploymentPlan.Size),
framework.RetryInterval, framework.Timeout)
Expect(err).To(BeNil())
}

0 comments on commit 20c90fe

Please sign in to comment.