Skip to content

Commit

Permalink
fixed error on system health status. bumped version to 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
darkcrux committed Oct 30, 2014
1 parent c4e080e commit 4299136
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAINTAINER Acaleph <[email protected]>
ADD https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip /tmp/consul.zip
RUN cd /bin && unzip /tmp/consul.zip && chmod +x /bin/consul && rm /tmp/consul.zip

ADD http://dl.bintray.com/darkcrux/generic/consul-alerts-0.1.0-linux-amd64.tar /tmp/consul-alerts.tar
ADD http://dl.bintray.com/darkcrux/generic/consul-alerts-0.1.1-linux-amd64.tar /tmp/consul-alerts.tar
RUN cd /bin && tar -xf /tmp/consul-alerts.tar && chmod +x /bin/consul-alerts && rm /tmp/consul-alerts.tar

EXPOSE 9000
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_NAME = consul-alerts
VERSION = 0.1.0
VERSION = 0.1.1

all: clean build

Expand Down Expand Up @@ -39,3 +39,9 @@ package: build-all
@tar cf build/tar/${APP_NAME}-${VERSION}-linux-386.tar -C build/bin/linux-386/${VERSION} ${APP_NAME}
@tar cf build/tar/${APP_NAME}-${VERSION}-linux-amd64.tar -C build/bin/linux-amd64/${VERSION} ${APP_NAME}
@tar cf build/tar/${APP_NAME}-${VERSION}-darwin-amd64.tar -C build/bin/darwin-amd64/${VERSION} ${APP_NAME}

release: package
@echo "--> Releasing version ${VERSION}"
curl -T "build/bin/linux-386/${VERSION}/${APP_NAME}" -u "${ACCESS_KEY}" "https://api.bintray.com/content/darkcrux/generic/consul-alerts/v${VERSION}/consul-alerts-${VERSION}-linux-386.tar"
curl -T "build/bin/linux-amd64/${VERSION}/${APP_NAME}" -u "${ACCESS_KEY}" "https://api.bintray.com/content/darkcrux/generic/consul-alerts/v${VERSION}/consul-alerts-${VERSION}-linux-amd64.tar"
curl -T "build/bin/darwin-amd64/${VERSION}/${APP_NAME}" -u "${ACCESS_KEY}" "https://api.bintray.com/content/darkcrux/generic/consul-alerts/v${VERSION}/consul-alerts-${VERSION}-darwin-386.tar"
2 changes: 1 addition & 1 deletion consul-alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/AcalephStorage/consul-alerts/Godeps/_workspace/src/github.com/docopt/docopt-go"
)

const version = "Consul Alerts 0.1.0"
const version = "Consul Alerts 0.1.1"
const usage = `Consul Alerts.
Usage:
Expand Down
47 changes: 47 additions & 0 deletions consul/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package consul

import (
"strconv"
"testing"
)

func TestLoadCustomValueForString(t *testing.T) {
var strVar string
input := "test-data"
data := []byte(input)
loadCustomValue(&strVar, data, ConfigTypeString)
if strVar != "test-data" {
t.Errorf("unable to parse %s to string", input)
}
}

func TestLoadCustomValueForBool(t *testing.T) {
var boolVar bool
input := []string{
"true",
"false",
"True",
"False",
"TRUE",
"FALSE",
}

for i, in := range input {
data := []byte(in)
loadCustomValue(&boolVar, data, ConfigTypeBool)
if i%2 == 0 && !boolVar {
t.Errorf("unable to parse %s to boolean", in)
}
}

}

func TestLoadCustomValueForInt(t *testing.T) {
var intVar int
input := "235"
data := []byte(input)
loadCustomValue(&intVar, data, ConfigTypeInt)
if in, _ := strconv.Atoi(input); in != intVar {
t.Errorf("unable to parse %s to int", input)
}
}
2 changes: 1 addition & 1 deletion notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (m Messages) Summary() (overallStatus string, pass, warn, fail int) {
}
}
if hasCritical {
overallStatus = SYSTEM_HEALTHY
overallStatus = SYSTEM_CRITICAL
} else if hasWarnings {
overallStatus = SYSTEM_UNSTABLE
} else {
Expand Down
66 changes: 66 additions & 0 deletions notifier/notifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package notifier

import "testing"

func TestMessageIsCritical(t *testing.T) {
message := Message{Status: "critical"}
if !message.IsCritical() {
t.Error("message should be critical")
}
}

func TestMessageIsWarning(t *testing.T) {
message := Message{Status: "warning"}
if !message.IsWarning() {
t.Error("message should be warning")
}
}

func TestMessageIsPassing(t *testing.T) {
message := Message{Status: "passing"}
if !message.IsPassing() {
t.Error("message should be passing")
}
}

func TestSystemIsHealthy(t *testing.T) {
messages := Messages{
Message{Status: "passing"},
Message{Status: "passing"},
Message{Status: "passing"},
Message{Status: "passing"},
Message{Status: "passing"},
}
stat, pass, warn, fail := messages.Summary()
if stat != SYSTEM_HEALTHY || pass != 5 || warn != 0 || fail != 0 {
t.Errorf("system should be healthy, status=%s, pass=%d, warn=%d, fail=%d", stat, pass, warn, fail)
}
}

func TestSystemIsCritical(t *testing.T) {
messages := Messages{
Message{Status: "passing"},
Message{Status: "passing"},
Message{Status: "critical"},
Message{Status: "passing"},
Message{Status: "warning"},
}
stat, pass, warn, fail := messages.Summary()
if stat != SYSTEM_CRITICAL || pass != 3 || warn != 1 || fail != 1 {
t.Errorf("system should be critical, status=%s, pass=%d, warn=%d, fail=%d", stat, pass, warn, fail)
}
}

func TestSystemIsUnstable(t *testing.T) {
messages := Messages{
Message{Status: "warning"},
Message{Status: "passing"},
Message{Status: "warning"},
Message{Status: "warning"},
Message{Status: "passing"},
}
stat, pass, warn, fail := messages.Summary()
if stat != SYSTEM_UNSTABLE || pass != 2 || warn != 3 || fail != 0 {
t.Errorf("system should be unstable, status=%s, pass=%d, warn=%d, fail=%d", stat, pass, warn, fail)
}
}

0 comments on commit 4299136

Please sign in to comment.