Skip to content

Commit

Permalink
Added make file, unit test and coveralls - connects to #10
Browse files Browse the repository at this point in the history
  • Loading branch information
devatherock committed Nov 21, 2020
1 parent 7fc9be9 commit ca74ee8
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 27 deletions.
62 changes: 39 additions & 23 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go_lang_image: &go_lang_image

slack_image: &slack_image
docker:
- image: devatherock/simple-slack:0.4.0
- image: devatherock/simple-slack:latest
auth:
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
Expand All @@ -30,28 +30,26 @@ executors:
version: 2.1
jobs:
test:
<<: *go_lang_image
<<: *resource_class
<<: *work_directory
executor: docker-executor
steps:
- checkout
- restore_cache:
keys:
- v1-pkg-cache
- run: go vet
- run: make check
build:
<<: *go_lang_image
<<: *resource_class
executor: docker-executor
environment:
CGO_ENABLED: 0
GOOS: linux
<<: *work_directory
steps:
- checkout
- restore_cache:
keys:
- v1-pkg-cache
- run: go build -o release/simpleslack
- run: |
make coveralls
make build
- save_cache:
paths:
- "/go/pkg"
Expand All @@ -61,23 +59,30 @@ jobs:
paths:
- release

publish_release:
executor: docker-executor
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: ~/simple-slack
- run: |
TAG=${CIRCLE_TAG#v}
DEV_TAG=${CIRCLE_SHA1:0:8}
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker pull devatherock/simple-slack:$DEV_TAG
docker tag devatherock/simple-slack:$DEV_TAG devatherock/simple-slack:$TAG
docker push devatherock/simple-slack:$TAG
notify_success:
<<: *slack_image
<<: *resource_class
environment:
TEXT: "Success: {{.CircleBuildUrl}} by {{.CircleUsername}}"
CHANNEL: general
TITLE: "Build completed"
steps:
- run: /bin/simpleslack -c "#33ad7f"
notify_failure:
<<: *slack_image
<<: *resource_class
environment:
TEXT: "Failure: {{.CircleBuildUrl}} by {{.CircleUsername}}"
steps:
- run:
name: Failure notification
command: /bin/simpleslack -c "#a1040c"
when: on_fail

workflows:
version: 2.1
Expand All @@ -90,28 +95,39 @@ workflows:
branches:
only: master
- docker/publish:
name: publish
executor: docker-executor
context:
- docker-credentials
requires:
- build
image: devatherock/simple-slack
attach-at: ~/simple-slack
tag: "0.4.0,latest"
tag: "${CIRCLE_SHA1:0:8},latest"
use-remote-docker: true
docker-username: DOCKER_USERNAME
- notify_success:
context:
- docker-credentials
- slack-webhook
requires:
- docker/publish
- notify_failure:
- publish
release:
jobs:
- publish_release:
context:
- docker-credentials
filters:
branches:
only: non-existent-branch
tags:
only: /^v[0-9\.]+$/
- notify_success:
context:
- docker-credentials
- slack-webhook
requires:
- docker/publish
- publish_release
pr_check:
jobs:
- test:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
release/
.project
*.iml
*.iml
coverage.out
coverage.html
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]
### Added
- make file
- First unit test
- Code coverage using coveralls

## [0.4.0] - 2020-06-13
### Added
- Some additional fields to the outgoing webhook payload. This is to support Zulip messaging.
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test:
go test -v -race -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
check:
gofmt -l -w -s .
go vet
go test -v -race -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
coveralls:
go test -v -race -coverprofile=coverage.out
go get github.com/mattn/goveralls
${GOPATH}/bin/goveralls -coverprofile=coverage.out
build:
go build -o release/simpleslack
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![CircleCI](https://circleci.com/gh/devatherock/simple-slack.svg?style=svg)](https://circleci.com/gh/devatherock/simple-slack)
[![Version](https://img.shields.io/docker/v/devatherock/simple-slack?sort=date)](https://hub.docker.com/r/devatherock/simple-slack/)
[![Version](https://img.shields.io/docker/v/devatherock/simple-slack?sort=semver)](https://hub.docker.com/r/devatherock/simple-slack/)
[![Coverage Status](https://coveralls.io/repos/github/devatherock/simple-slack/badge.svg?branch=master)](https://coveralls.io/github/devatherock/simple-slack?branch=master)
[![Docker Pulls](https://img.shields.io/docker/pulls/devatherock/simple-slack.svg)](https://hub.docker.com/r/devatherock/simple-slack/)
[![Docker Image Size](https://img.shields.io/docker/image-size/devatherock/simple-slack.svg?sort=date)](https://hub.docker.com/r/devatherock/simple-slack/)
[![Docker Image Layers](https://img.shields.io/microbadger/layers/devatherock/simple-slack.svg)](https://microbadger.com/images/devatherock/simple-slack)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module github.com/devatherock/simple-slack
go 1.14

require (
github.com/urfave/cli/v2 v2.2.0
)
github.com/mattn/goveralls v0.0.7 // indirect
github.com/urfave/cli/v2 v2.2.0
)
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/mattn/goveralls v0.0.7 h1:vzy0i4a2iDzEFMdXIxcanRadkr0FBvSBKUmj0P8SPlQ=
github.com/mattn/goveralls v0.0.7/go.mod h1:h8b4ow6FxSPMQHF6o2ve3qsclnffZjYTNEKmLesRwqw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand All @@ -11,5 +13,23 @@ github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA=
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 h1:SjQ2+AKWgZLc1xej6WSzL+Dfs5Uyd5xcZH1mGC411IA=
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
28 changes: 28 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"testing"
)

func TestContains(test *testing.T) {
secretsArray := []string{"PLUGIN_WEBHOOK", "SLACK_WEBHOOK", "WEBHOOK"}
cases := []struct {
envVariable string
expected bool
}{
{"PLUGIN_WEBHOOK", true},
{"SLACK_WEBHOOK", true},
{"WEBHOOK", true},
{"PARAMETER_TEXT", false},
{"PARAMETER_TITLE", false},
{"PARAMETER_CHANNEL", false},
}

for _, data := range cases {
actual := contains(secretsArray, data.envVariable)
if actual != data.expected {
test.Logf("Expected: %t, Actual: %t", data.expected, actual)
test.Fail()
}
}
}

0 comments on commit ca74ee8

Please # to comment.