From b48ee522b4aeb86d00e1db74f09475fa96d7ff02 Mon Sep 17 00:00:00 2001 From: Stian Grindvoll Date: Wed, 22 Nov 2017 00:46:11 +0100 Subject: [PATCH] Add testing framework and simple first test (#2) --- .travis.yml | 6 ++++++ Gopkg.lock | 20 +++++++++++++++++++- Makefile | 9 +++++++-- rmq/message_test.go | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 rmq/message_test.go diff --git a/.travis.yml b/.travis.yml index 8fe2587..8d62305 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,12 @@ sudo: false go: - 1.x +script: + - make + +before_deploy: + - make build-all + deploy: provider: releases api_key: diff --git a/Gopkg.lock b/Gopkg.lock index 65c3fd3..83339cc 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,6 +1,12 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. +[[projects]] + name = "github.com/davecgh/go-spew" + packages = ["spew"] + revision = "346938d642f2ec3594ed81d874461961cd0faa76" + version = "v1.1.0" + [[projects]] name = "github.com/inconshreveable/mousetrap" packages = ["."] @@ -13,6 +19,12 @@ revision = "e790cca94e6cc75c7064b1332e63811d4aae1a53" version = "v1.1" +[[projects]] + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + [[projects]] name = "github.com/spf13/cobra" packages = ["."] @@ -31,9 +43,15 @@ packages = ["."] revision = "ff791c2d22d3f1588b4e2cc71a9fba5e1da90654" +[[projects]] + name = "github.com/stretchr/testify" + packages = ["assert"] + revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0" + version = "v1.1.4" + [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "13f7e0c320131fb680e531688ff4b3f5ab50bc726033cba5f5c23e65b514d7d4" + inputs-digest = "2896c159b69f631551a2b9d500716df12eaf86dd05d26b689c08e24138c77b84" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Makefile b/Makefile index d46972b..79f68e5 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ VERSION := $(shell git describe --tags) BUILD_DIR?=$(shell pwd)/build NAME=rio +DIRECTORIES=./ ./cmd ./rmq ./file -all: tools deps build-all compress +all: tools deps test tools: go get -u github.com/golang/dep/cmd/dep @@ -11,6 +12,10 @@ tools: deps: dep ensure +test: + go vet ${DIRECTORIES} + go test -v ${DIRECTORIES} + build: go build -o ${NAME} -ldflags "-X main.version=${VERSION}" main.go @@ -22,7 +27,7 @@ build-all: -output="${BUILD_DIR}/${NAME}-${VERSION}-{{.OS}}-{{.Arch}}" compress: - gzip -v ${BUILD_DIR}/* + gzip -f -v ${BUILD_DIR}/* clean: rm -rf ./build diff --git a/rmq/message_test.go b/rmq/message_test.go new file mode 100644 index 0000000..32751cd --- /dev/null +++ b/rmq/message_test.go @@ -0,0 +1,33 @@ +// Copyright © 2017 Meltwater +// +// 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 rmq + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewMessageFromAttrs(t *testing.T) { + var headers = make(map[string]string) + headers["amqp.routingKey"] = "routingKey from tarball header" + headers["myHeaderString"] = "myString" + + m := *NewMessageFromAttrs([]byte("Message"), headers) + + assert.Equal(t, "routingKey from tarball header", m.RoutingKey) + assert.Equal(t, []byte("Message"), m.Body) + assert.Equal(t, "myString", m.Headers["myHeaderString"]) +}