diff --git a/.ci/check-gofmt b/.ci/check-gofmt new file mode 100755 index 0000000..4a1c0b2 --- /dev/null +++ b/.ci/check-gofmt @@ -0,0 +1,8 @@ +#!/bin/bash + +result="$(gofmt -s -l . | grep -v '^vendor/' )" +if [ -n "$result" ]; then + echo "Go code is not formatted, run 'gofmt -s -w .'" >&2 + echo "$result" + exit 1 +fi diff --git a/.ci/check-testfiles b/.ci/check-testfiles new file mode 100755 index 0000000..132ff73 --- /dev/null +++ b/.ci/check-testfiles @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# checks if every desired package has test files + +import os +import re +import sys + +source_re = re.compile(".*\.go") +test_re = re.compile(".*_test\.go") +missing = False + +for root, dirs, files in os.walk("."): + # ignore some paths + if root == "." or root.startswith("./vendor") or root.startswith("./."): + continue + + # source files but not test files? + if len(filter(source_re.match, files)) > 0 and len(filter(test_re.match, files)) == 0: + print("no test files for {}".format(root)) + missing = True + +if missing: + sys.exit(1) +else: + print("every package has test files") diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4b2b009 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,30 @@ +image: golang:latest +stages: + - build + - test + +before_script: + - mkdir -p /go/src/git.sum7.eu/genofire/ + - cp -R /builds/genofire/logmania /go/src/git.sum7.eu/genofire/logmania + - cd /go/src/git.sum7.eu/genofire/logmania + - go get -d -t ./... + +build-my-project: + stage: build + script: + - go install git.sum7.eu/genofire/logmania + artifacts: + paths: + - /go/bin/logmania + +test-my-project: + stage: test + script: + - ./.ci/check-gofmt + - ./.ci/check-testfiles + - go test $(go list ./... | grep -v /vendor/) -v -coverprofile .testCoverage.txt + +test-race-my-project: + stage: test + script: + - go test -race ./... diff --git a/bot/filter.go b/bot/filter.go index ede3450..f51edb0 100644 --- a/bot/filter.go +++ b/bot/filter.go @@ -11,7 +11,7 @@ func NewFilter(db *database.DB) *Command { Name: "filter", Description: "list and configurate regex filter for channel by message content", Commands: []*Command{ - &Command{ + { Name: "add", Description: "add regex filter for channel: [channel] regex", Action: func(from string, params []string) string { @@ -32,7 +32,7 @@ func NewFilter(db *database.DB) *Command { return fmt.Sprintf("add regex for \"%s\" to %s", of, regex) }, }, - &Command{ + { Name: "del", Description: "del regex filter for channel: [channel] regex", Action: func(from string, params []string) string { @@ -50,7 +50,7 @@ func NewFilter(db *database.DB) *Command { return "deleted" }, }, - &Command{ + { Name: "all", Description: "list of all channels", Action: func(from string, params []string) string { @@ -64,7 +64,7 @@ func NewFilter(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list of given channel: channel", Action: func(from string, params []string) string { diff --git a/bot/hostname.go b/bot/hostname.go index 66fbd3d..0e684f5 100644 --- a/bot/hostname.go +++ b/bot/hostname.go @@ -12,7 +12,7 @@ func NewHostname(db *database.DB) *Command { Name: "hostname", Description: "alternative short (host)names for long IP-Addresses or URLs (and time of last recieved input)", Commands: []*Command{ - &Command{ + { Name: "set", Description: "set or replace a hostname: IPAddress/Hostname NewHostname", Action: func(from string, params []string) string { @@ -31,7 +31,7 @@ func NewHostname(db *database.DB) *Command { return fmt.Sprintf("set for %s the hostname %s", addr, name) }, }, - &Command{ + { Name: "del", Description: "delete a hostname: IPAddress/Hostname", Action: func(from string, params []string) string { diff --git a/bot/priority.go b/bot/priority.go index 68b52c8..6ade64a 100644 --- a/bot/priority.go +++ b/bot/priority.go @@ -13,7 +13,7 @@ func NewPriority(db *database.DB) *Command { Name: "priority", Description: "list and configurate priority in channel", Commands: []*Command{ - &Command{ + { Name: "set", Description: "set max priority of channel: [channel] Priority", Action: func(from string, params []string) string { @@ -43,7 +43,7 @@ func NewPriority(db *database.DB) *Command { return fmt.Sprintf("set filter for %s to %s", to, max.String()) }, }, - &Command{ + { Name: "all", Description: "list of all channels", Action: func(from string, params []string) string { @@ -54,7 +54,7 @@ func NewPriority(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list of given channel: channel", Action: func(from string, params []string) string { diff --git a/bot/replace.go b/bot/replace.go index 45df105..c26cff4 100644 --- a/bot/replace.go +++ b/bot/replace.go @@ -11,7 +11,7 @@ func NewReplace(db *database.DB) *Command { Name: "replace", Description: "list and configurate replace content of message for channel", Commands: []*Command{ - &Command{ + { Name: "add", Description: "add regex replace for channel: [channel] regex replace", Action: func(from string, params []string) string { @@ -34,7 +34,7 @@ func NewReplace(db *database.DB) *Command { return fmt.Sprintf("add replace in \"%s\" for \"%s\" to \"%s\"", of, regex, value) }, }, - &Command{ + { Name: "del", Description: "del regex replace for channel: [channel] regex replace", Action: func(from string, params []string) string { @@ -54,7 +54,7 @@ func NewReplace(db *database.DB) *Command { }, }, - &Command{ + { Name: "all", Description: "list of all channels", Action: func(from string, params []string) string { @@ -68,7 +68,7 @@ func NewReplace(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list of given channel: channel", Action: func(from string, params []string) string { diff --git a/bot/send.go b/bot/send.go index 381f0b8..bdb41f4 100644 --- a/bot/send.go +++ b/bot/send.go @@ -11,7 +11,7 @@ func NewSend(db *database.DB) *Command { Name: "send", Description: "list and configurate destination for hostnames", Commands: []*Command{ - &Command{ + { Name: "add", Description: "add a destination for host with: IPAddress/Hostname [to]", Action: func(from string, params []string) string { @@ -43,7 +43,7 @@ func NewSend(db *database.DB) *Command { return fmt.Sprintf("added %s in list of %s", to, host) }, }, - &Command{ + { Name: "del", Description: "del a destination for host with: IPAddress/Hostname [to]", Action: func(from string, params []string) string { @@ -63,7 +63,7 @@ func NewSend(db *database.DB) *Command { return "not found host" }, }, - &Command{ + { Name: "all", Description: "list of all hosts with there channels", Action: func(from string, params []string) string { @@ -85,7 +85,7 @@ func NewSend(db *database.DB) *Command { return msg }, }, - &Command{ + { Name: "channel", Description: "list all host of given channel: channel", Action: func(from string, params []string) string {