From 06d61b6b71db8ebc0b74d1837c43a497ba164d89 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Wed, 14 Feb 2018 10:46:43 +0100 Subject: [PATCH] [TASK] add CI circleci and codecov + coveralls --- .test-coverage | 33 +++++++++++++++++++++++++++++++++ README.md | 6 ++++++ circle.yml | 41 +++++++++++++++++++++++++++++++++++++++++ daemon/tester/bot.go | 4 ++-- daemon/tester/status.go | 2 +- main.go | 2 +- messages/iq_utils.go | 7 +++---- messages/jid_test.go | 36 ++++++++++++++++++------------------ 8 files changed, 105 insertions(+), 26 deletions(-) create mode 100755 .test-coverage create mode 100644 circle.yml diff --git a/.test-coverage b/.test-coverage new file mode 100755 index 0000000..c6bd28b --- /dev/null +++ b/.test-coverage @@ -0,0 +1,33 @@ +#!/bin/bash +# Issue: https://github.com/mattn/goveralls/issues/20 +# Source: https://github.com/uber/go-torch/blob/63da5d33a225c195fea84610e2456d5f722f3963/.test-cover.sh +CI=$1 +echo "run for $CI" + +if [ "$CI" == "circle-ci" ]; then + cd ${GOPATH}/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} +fi + +echo "mode: count" > profile.cov +FAIL=0 + +# Standard go tooling behavior is to ignore dirs with leading underscors +for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); +do + if ls $dir/*.go &> /dev/null; then + go test -v -covermode=count -coverprofile=profile.tmp $dir || FAIL=$? + if [ -f profile.tmp ] + then + tail -n +2 < profile.tmp >> profile.cov + rm profile.tmp + fi + fi +done + +# Failures have incomplete results, so don't send +if [ "$FAIL" -eq 0 ]; then + goveralls -service=$CI -v -coverprofile=profile.cov + bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov +fi + +exit $FAIL diff --git a/README.md b/README.md index 278f088..885c103 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ # yaja (Yet Another JAbber implementation) +[![CircleCI](https://circleci.com/gh/genofire/yaja/tree/master.svg?style=shield)](https://circleci.com/gh/genofire/yaja/tree/master) +[![Coverage Status](https://coveralls.io/repos/github/genofire/yaja/badge.svg?branch=master)](https://coveralls.io/github/genofire/yaja?branch=master) +[![codecov](https://codecov.io/gh/genofire/yaja/branch/master/graph/badge.svg)](https://codecov.io/gh/genofire/yaja) +[![Go Report Card](https://goreportcard.com/badge/github.com/genofire/yaja)](https://goreportcard.com/report/github.com/genofire/yaja) [![chat on our conference room](https://camo.githubusercontent.com/a839cc0a3d4dac7ec82237381b165dd144365b6d/68747470733a2f2f74696e7975726c2e636f6d2f6a6f696e7468656d7563)](https://conversations.im/j/yaja@conference.chat.sum7.eu) ## Features - Messages XML Library (first version - PR are welcome) - Full RFC 6120 (XMPP - Core) + - XEP-0199: XMPP Ping - Client Library (WIP) - Stream: TLS Required - SASL-Auth (PLAIN, DIGEST-MD5) @@ -29,6 +34,7 @@ all implementation of all comman (RFCs and XEPs) xml element **Version** - RFC 6120 (XMPP - Core) +- XEP-0199: XMPP Ping ### Client diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..8b0e88b --- /dev/null +++ b/circle.yml @@ -0,0 +1,41 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/golang:latest + working_directory: /go/src/dev.sum7.eu/genofire/yaja + steps: + - checkout + - run: go get -t -d -v ./... + - run: go install dev.sum7.eu/genofire/yaja + - store_artifacts: + path: /go/bin/ + destination: yaja + test: + docker: + - image: circleci/golang:latest + working_directory: /go/src/dev.sum7.eu/genofire/yaja + steps: + - checkout + - run: go get -t -d -v ./... + - run: go get github.com/mattn/goveralls + - run: go get golang.org/x/tools/cmd/cover + - run: ./.test-coverage circle-ci + - store_test_results: + path: ./ + destination: profile.cov + test_race: + docker: + - image: circleci/golang:latest + working_directory: /go/src/dev.sum7.eu/genofire/yaja + steps: + - checkout + - run: go get -t -d -v ./... + - run: go test -race ./... +workflows: + version: 2 + build_and_tests: + jobs: + - build + - test + - test_race diff --git a/daemon/tester/bot.go b/daemon/tester/bot.go index 9b1d0ff..d691237 100644 --- a/daemon/tester/bot.go +++ b/daemon/tester/bot.go @@ -142,7 +142,7 @@ func (t *Tester) StartBot(status *Status) { } func botAllowed(list []*messages.JID, toConvert map[string]interface{}) []*messages.JID { alist := list - for jid, _ := range toConvert { + for jid := range toConvert { alist = append(alist, messages.NewJID(jid)) } return alist @@ -173,7 +173,7 @@ func botAdmin(cmd []string, log *log.Entry, status *Status, from *messages.JID, } } else { if len(cmd) == 1 && cmd[0] == "list" { - for jid, _ := range status.account.Admins { + for jid := range status.account.Admins { if msg == "" { msg += "admins are: " + jid } else { diff --git a/daemon/tester/status.go b/daemon/tester/status.go index 8bd298e..7c9eaf2 100644 --- a/daemon/tester/status.go +++ b/daemon/tester/status.go @@ -39,7 +39,7 @@ func (s *Status) Disconnect(reason string) { Type: messages.MessageTypeChat, Body: fmt.Sprintf("you recieve a notify that '%s' disconnect: %s", s.JID.Full(), reason), } - for jid, _ := range s.account.Admins { + for jid := range s.account.Admins { msg.To = messages.NewJID(jid) if err := s.backupClient.Send(msg); err != nil { s.client.Send(msg) diff --git a/main.go b/main.go index e7be7f7..31de548 100644 --- a/main.go +++ b/main.go @@ -4,4 +4,4 @@ import "dev.sum7.eu/genofire/yaja/cmd" func main() { cmd.Execute() -} \ No newline at end of file +} diff --git a/messages/iq_utils.go b/messages/iq_utils.go index 356f28b..8522c9a 100644 --- a/messages/iq_utils.go +++ b/messages/iq_utils.go @@ -1,17 +1,16 @@ package messages -// which XEP ???? - import ( "encoding/xml" ) -// where to put: (server part debug? is it part) - +// XEP-0199: XMPP Ping type Ping struct { XMLName xml.Name `xml:"urn:xmpp:ping ping"` } +// which XEP ???? +// where to put: (server part debug? is it part) type IQPrivateQuery struct { XMLName xml.Name `xml:"jabber:iq:private query"` Body []byte `xml:",innerxml"` diff --git a/messages/jid_test.go b/messages/jid_test.go index 7baae4f..d6ff2c4 100644 --- a/messages/jid_test.go +++ b/messages/jid_test.go @@ -12,69 +12,69 @@ func TestNewJID(t *testing.T) { assert := assert.New(t) checkList := map[string]*JID{ - "juliet@example.com": &JID{ + "juliet@example.com": { Local: "juliet", Domain: "example.com", }, - "juliet@example.com/foo": &JID{ + "juliet@example.com/foo": { Local: "juliet", Domain: "example.com", Resource: "foo", }, - "juliet@example.com/foo bar": &JID{ + "juliet@example.com/foo bar": { Local: "juliet", Domain: "example.com", Resource: "foo bar", }, - "juliet@example.com/foo@bar": &JID{ + "juliet@example.com/foo@bar": { Local: "juliet", Domain: "example.com", Resource: "foo@bar", }, - "foo\\20bar@example.com": &JID{ + "foo\\20bar@example.com": { Local: "foo\\20bar", Domain: "example.com", }, - "fussball@example.com": &JID{ + "fussball@example.com": { Local: "fussball", Domain: "example.com", }, - "fußball@example.com": &JID{ + "fußball@example.com": { Local: "fußball", Domain: "example.com", }, - "π@example.com": &JID{ + "π@example.com": { Local: "π", Domain: "example.com", }, - "Σ@example.com/foo": &JID{ + "Σ@example.com/foo": { Local: "Σ", Domain: "example.com", Resource: "foo", }, - "σ@example.com/foo": &JID{ + "σ@example.com/foo": { Local: "σ", Domain: "example.com", Resource: "foo", }, - "ς@example.com/foo": &JID{ + "ς@example.com/foo": { Local: "ς", Domain: "example.com", Resource: "foo", }, - "king@example.com/♚": &JID{ + "king@example.com/♚": { Local: "king", Domain: "example.com", Resource: "♚", }, - "example.com": &JID{ + "example.com": { Domain: "example.com", }, - "example.com/foobar": &JID{ + "example.com/foobar": { Domain: "example.com", Resource: "foobar", }, - "a.example.com/b@example.net": &JID{ + "a.example.com/b@example.net": { Domain: "a.example.com", Resource: "b@example.net", }, @@ -112,16 +112,16 @@ func TestJIDBare(t *testing.T) { assert := assert.New(t) checkList := map[string]*JID{ - "aaa@example.com": &JID{ + "aaa@example.com": { Local: "aaa", Domain: "example.com", }, - "aab@example.com": &JID{ + "aab@example.com": { Local: "aab", Domain: "example.com", Resource: "foo", }, - "example.com": &JID{ + "example.com": { Domain: "example.com", Resource: "foo", },