Skip to content

Commit

Permalink
replace golangci-lint w/staticcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kolberg <amd.prophet@gmail.com>
  • Loading branch information
amdprophet committed May 6, 2022
1 parent 593bc2a commit e31a6ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/lint.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/static-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: static-check

on: [push, pull_request]

jobs:
staticcheck:
name: staticcheck (project)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: dominikh/staticcheck-action@v1.2.0
with:
version: "2022.1"
env:
GO_VERSION: 1.18.1
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type HandlerConfig struct {
sensu.PluginConfig
authToken string
dedupKeyTemplate string
statusMapJson string
statusMapJSON string
summaryTemplate string
teamName string
teamSuffix string
Expand Down Expand Up @@ -77,7 +77,7 @@ var (
Argument: "status-map",
Shorthand: "s",
Usage: "The status map used to translate a Sensu check status to a PagerDuty severity, can be set with PAGERDUTY_STATUS_MAP",
Value: &config.statusMapJson,
Value: &config.statusMapJSON,
Default: "",
},
{
Expand Down Expand Up @@ -159,7 +159,7 @@ func checkArgs(event *corev2.Event) error {
}

func manageIncident(event *corev2.Event) error {
severity, err := getPagerDutySeverity(event, config.statusMapJson)
severity, err := getPagerDutySeverity(event, config.statusMapJSON)
if err != nil {
return err
}
Expand Down Expand Up @@ -243,12 +243,12 @@ func getPagerDutyDedupKey(event *corev2.Event) (string, error) {
return templates.EvalTemplate("dedupKey", config.dedupKeyTemplate, event)
}

func getPagerDutySeverity(event *corev2.Event, statusMapJson string) (string, error) {
func getPagerDutySeverity(event *corev2.Event, statusMapJSON string) (string, error) {
var statusMap map[uint32]string
var err error

if len(statusMapJson) > 0 {
statusMap, err = parseStatusMap(statusMapJson)
if len(statusMapJSON) > 0 {
statusMap, err = parseStatusMap(statusMapJSON)
if err != nil {
return "", err
}
Expand All @@ -272,11 +272,11 @@ func getPagerDutySeverity(event *corev2.Event, statusMapJson string) (string, er
return severity, nil
}

func parseStatusMap(statusMapJson string) (map[uint32]string, error) {
func parseStatusMap(statusMapJSON string) (map[uint32]string, error) {
validPagerDutySeverities := map[string]bool{"info": true, "critical": true, "warning": true, "error": true}

statusMap := eventStatusMap{}
err := json.Unmarshal([]byte(statusMapJson), &statusMap)
err := json.Unmarshal([]byte(statusMapJSON), &statusMap)
if err != nil {
return nil, err
}
Expand Down
17 changes: 9 additions & 8 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"encoding/json"

corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/stretchr/testify/assert"
"os"
"testing"

corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/stretchr/testify/assert"
)

var (
Expand Down Expand Up @@ -58,10 +59,10 @@ func Test_ParseStatusMap_InvalidSeverity(t *testing.T) {
}

func Test_GetPagerDutySeverity_Success(t *testing.T) {
statusMapJson := "{\"info\":[130,10],\"error\":[4]}"
statusMapJSON := "{\"info\":[130,10],\"error\":[4]}"

eventWithStatus.Check.Status = 10
pagerDutySeverity, err := getPagerDutySeverity(&eventWithStatus, statusMapJson)
pagerDutySeverity, err := getPagerDutySeverity(&eventWithStatus, statusMapJSON)
assert.Nil(t, err)
assert.Equal(t, "info", pagerDutySeverity)
}
Expand All @@ -81,19 +82,19 @@ func Test_GetPagerDutySeverity_NoStatusMapLowStatus(t *testing.T) {
}

func Test_GetPagerDutySeverity_InvalidStatusMap(t *testing.T) {
statusMapJson := "{\"info\":[130,10],\"error\"[4]}"
statusMapJSON := "{\"info\":[130,10],\"error\"[4]}"

eventWithStatus.Check.Status = 2
pagerDutySeverity, err := getPagerDutySeverity(&eventWithStatus, statusMapJson)
pagerDutySeverity, err := getPagerDutySeverity(&eventWithStatus, statusMapJSON)
assert.NotNil(t, err)
assert.Empty(t, pagerDutySeverity)
}

func Test_GetPagerDutySeverity_StatusMapSeverityNotInMap(t *testing.T) {
statusMapJson := "{\"info\":[130,10],\"error\":[4]}"
statusMapJSON := "{\"info\":[130,10],\"error\":[4]}"

eventWithStatus.Check.Status = 2
pagerDutySeverity, err := getPagerDutySeverity(&eventWithStatus, statusMapJson)
pagerDutySeverity, err := getPagerDutySeverity(&eventWithStatus, statusMapJSON)
assert.Nil(t, err)
assert.Equal(t, "critical", pagerDutySeverity)
}
Expand Down

0 comments on commit e31a6ad

Please sign in to comment.