diff --git a/conf/configuration.go b/conf/configuration.go index 57516d2d..8329ec19 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -1,13 +1,14 @@ package conf import ( - "github.com/opsgenie/oec/git" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" "os" "path/filepath" "strings" "time" + + "github.com/opsgenie/oec/git" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) const ( @@ -101,9 +102,9 @@ func ReadConfFile() (*Configuration, error) { if err != nil { return nil, err } - + if os.Getenv("OEC_API_KEY") != "" { - conf.ApiKey = os.Getenv("OEC_API_KEY") + conf.ApiKey = os.Getenv("OEC_API_KEY") } err = validateConfiguration(conf) @@ -194,7 +195,7 @@ func readConfFileFromSource(confSourceType string) (*Configuration, error) { case LocalSourceType: confFilepath := os.Getenv("OEC_CONF_LOCAL_FILEPATH") - if len(confFilepath) <= 0 { + if len(confFilepath) == 0 { confFilepath = addHomeDirPrefix(defaultConfFilepath) } else { confFilepath = addHomeDirPrefix(confFilepath) diff --git a/conf/configuration_test.go b/conf/configuration_test.go index 83535839..cf33d9f2 100644 --- a/conf/configuration_test.go +++ b/conf/configuration_test.go @@ -1,12 +1,13 @@ package conf import ( + "os" + "testing" + "github.com/opsgenie/oec/git" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" - "os" - "testing" ) var readConfigurationFromGitCalled = false @@ -46,7 +47,7 @@ func expectedConf() *Configuration { "-apiKey", expectedConf.ApiKey, "-opsgenieUrl", expectedConf.BaseUrl, "-logLevel", "INFO"}, - expectedConf.GlobalArgs... + expectedConf.GlobalArgs..., ) if expectedConf.LogrusLevel == 0 { @@ -107,19 +108,19 @@ const testLocalConfFilePath = "/path/to/test/conf/file.json" func mockReadConfigurationFromGit(owner, repo, filepath, token string) (*Configuration, error) { readConfigurationFromGitCalled = true - if len(owner) <= 0 { + if len(owner) == 0 { return nil, errors.New("Owner was empty.") } - if len(repo) <= 0 { + if len(repo) == 0 { return nil, errors.New("Repo was empty.") } - if len(filepath) <= 0 { + if len(filepath) == 0 { return nil, errors.New("Filepath was empty.") } - if len(token) <= 0 { + if len(token) == 0 { return nil, errors.New("Token was empty.") } diff --git a/conf/from_git.go b/conf/from_git.go index 51ee3b8c..e122f1c3 100644 --- a/conf/from_git.go +++ b/conf/from_git.go @@ -1,9 +1,10 @@ package conf import ( - "github.com/opsgenie/oec/git" "os" "path/filepath" + + "github.com/opsgenie/oec/git" ) var cloneMasterFunc = git.CloneMaster diff --git a/conf/from_git_test.go b/conf/from_git_test.go index d8d0a6d1..f013ba79 100644 --- a/conf/from_git_test.go +++ b/conf/from_git_test.go @@ -1,10 +1,11 @@ package conf import ( + "testing" + "github.com/opsgenie/oec/git" "github.com/opsgenie/oec/util" "github.com/stretchr/testify/assert" - "testing" ) func TestReadConfigurationFromGit(t *testing.T) { diff --git a/conf/from_local_test.go b/conf/from_local_test.go index 33a1b028..8b5aa494 100644 --- a/conf/from_local_test.go +++ b/conf/from_local_test.go @@ -1,10 +1,11 @@ package conf import ( - "github.com/opsgenie/oec/util" - "github.com/stretchr/testify/assert" "os" "testing" + + "github.com/opsgenie/oec/util" + "github.com/stretchr/testify/assert" ) func TestReadConfigurationFromLocal(t *testing.T) { diff --git a/conf/util.go b/conf/util.go index ed0f5737..94234719 100644 --- a/conf/util.go +++ b/conf/util.go @@ -2,16 +2,17 @@ package conf import ( "encoding/json" - "github.com/opsgenie/oec/git" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "gopkg.in/yaml.v2" "io/ioutil" "os" fpath "path/filepath" "runtime" "strings" "time" + + "github.com/opsgenie/oec/git" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "gopkg.in/yaml.v2" ) const unknownFileExtErrMessage = "Unknown configuration file extension[%s]. Only \".json\" and \".yml(.yaml)\" types are allowed." diff --git a/conf/util_test.go b/conf/util_test.go index 5d05d1dd..e6c4a73f 100644 --- a/conf/util_test.go +++ b/conf/util_test.go @@ -2,10 +2,11 @@ package conf import ( "fmt" - "github.com/opsgenie/oec/util" - "github.com/stretchr/testify/assert" "os" "testing" + + "github.com/opsgenie/oec/util" + "github.com/stretchr/testify/assert" ) func TestReadConfigurationFromJsonFile(t *testing.T) { diff --git a/git/clone.go b/git/clone.go index cb88c879..1e448ea9 100644 --- a/git/clone.go +++ b/git/clone.go @@ -1,11 +1,12 @@ package git import ( + "io/ioutil" + "os" + "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh" - "io/ioutil" - "os" ) var gitCloneMasterFunc = gitCloneMaster diff --git a/git/repository.go b/git/repository.go index bec075e7..388329f5 100644 --- a/git/repository.go +++ b/git/repository.go @@ -1,12 +1,13 @@ package git import ( + "os" + "sync" + "github.com/opsgenie/oec/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" "gopkg.in/src-d/go-git.v4" - "os" - "sync" ) type GitOptions struct { diff --git a/main/main.go b/main/main.go index b54fc9ea..94514f11 100644 --- a/main/main.go +++ b/main/main.go @@ -3,12 +3,6 @@ package main import ( "flag" "fmt" - "github.com/opsgenie/oec/conf" - "github.com/opsgenie/oec/queue" - "github.com/opsgenie/oec/util" - "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/sirupsen/logrus" - "gopkg.in/natefinch/lumberjack.v2" "io" "net/http" "os" @@ -18,6 +12,13 @@ import ( "strconv" "syscall" "time" + + "github.com/opsgenie/oec/conf" + "github.com/opsgenie/oec/queue" + "github.com/opsgenie/oec/util" + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/sirupsen/logrus" + "gopkg.in/natefinch/lumberjack.v2" ) var metricAddr = flag.String("oec-metrics", "7070", "The address to listen on for HTTP requests.") @@ -79,14 +80,11 @@ func main() { signals := make(chan os.Signal, 1) signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) - select { - case <-signals: - logrus.Infof("OEC will be stopped gracefully.") - err := queueProcessor.StopProcessing() - if err != nil { - logrus.Fatalln(err) - } + <-signals + logrus.Infof("OEC will be stopped gracefully.") + err = queueProcessor.StopProcessing() + if err != nil { + logrus.Fatalln(err) } - os.Exit(0) } diff --git a/queue/job.go b/queue/job.go index 569d6910..985f4b74 100644 --- a/queue/job.go +++ b/queue/job.go @@ -1,12 +1,13 @@ package queue import ( + "sync" + "time" + "github.com/aws/aws-sdk-go/service/sqs" "github.com/opsgenie/oec/runbook" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "sync" - "time" ) const ( diff --git a/queue/job_test.go b/queue/job_test.go index ca2f9ca9..93a281e2 100644 --- a/queue/job_test.go +++ b/queue/job_test.go @@ -2,15 +2,16 @@ package queue import ( "encoding/json" - "github.com/aws/aws-sdk-go/service/sqs" - "github.com/opsgenie/oec/runbook" - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "net/http/httptest" "sync" "testing" + + "github.com/aws/aws-sdk-go/service/sqs" + "github.com/opsgenie/oec/runbook" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) var mockActionResultPayload = &runbook.ActionResultPayload{Action: "MockAction"} diff --git a/queue/poller.go b/queue/poller.go index dce17394..c0470eac 100644 --- a/queue/poller.go +++ b/queue/poller.go @@ -1,6 +1,13 @@ package queue import ( + "io" + "os" + "path/filepath" + "strconv" + "sync" + "time" + "github.com/aws/aws-sdk-go/service/sqs" "github.com/opsgenie/oec/conf" "github.com/opsgenie/oec/git" @@ -8,12 +15,6 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "gopkg.in/natefinch/lumberjack.v2" - "io" - "os" - "path/filepath" - "strconv" - "sync" - "time" ) type Poller interface { diff --git a/queue/poller_test.go b/queue/poller_test.go index ed53b457..ebb4a0c4 100644 --- a/queue/poller_test.go +++ b/queue/poller_test.go @@ -1,15 +1,16 @@ package queue import ( + "io" + "sync" + "testing" + "github.com/aws/aws-sdk-go/service/sqs" "github.com/opsgenie/oec/conf" "github.com/opsgenie/oec/git" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" - "io" - "sync" - "testing" ) var mockPollerConf = &conf.PollerConf{ diff --git a/queue/queue_message.go b/queue/queue_message.go index 40c79bf5..588ea5d6 100644 --- a/queue/queue_message.go +++ b/queue/queue_message.go @@ -3,14 +3,15 @@ package queue import ( "encoding/json" "fmt" + "io" + "time" + "github.com/aws/aws-sdk-go/service/sqs" "github.com/opsgenie/oec/conf" "github.com/opsgenie/oec/git" "github.com/opsgenie/oec/runbook" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "io" - "time" ) type QueueMessage interface { diff --git a/queue/queue_message_test.go b/queue/queue_message_test.go index dd4e53a3..f17d721c 100644 --- a/queue/queue_message_test.go +++ b/queue/queue_message_test.go @@ -2,16 +2,17 @@ package queue import ( "bytes" + "io" + "math/rand" + "testing" + "time" + "github.com/aws/aws-sdk-go/service/sqs" "github.com/opsgenie/oec/conf" "github.com/opsgenie/oec/git" "github.com/opsgenie/oec/runbook" "github.com/pkg/errors" "github.com/stretchr/testify/assert" - "io" - "math/rand" - "testing" - "time" ) var ( diff --git a/queue/queue_processor.go b/queue/queue_processor.go index d5785e9e..e0eef083 100644 --- a/queue/queue_processor.go +++ b/queue/queue_processor.go @@ -3,18 +3,19 @@ package queue import ( "bytes" "encoding/json" - "github.com/opsgenie/oec/conf" - "github.com/opsgenie/oec/git" - "github.com/opsgenie/oec/retryer" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "gopkg.in/natefinch/lumberjack.v2" "io" "io/ioutil" "net/http" "strconv" "sync" "time" + + "github.com/opsgenie/oec/conf" + "github.com/opsgenie/oec/git" + "github.com/opsgenie/oec/retryer" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "gopkg.in/natefinch/lumberjack.v2" ) var UserAgentHeader string diff --git a/queue/queue_processor_test.go b/queue/queue_processor_test.go index 18569aa1..69ff9a79 100644 --- a/queue/queue_processor_test.go +++ b/queue/queue_processor_test.go @@ -3,11 +3,6 @@ package queue import ( "bytes" "encoding/json" - "github.com/opsgenie/oec/conf" - "github.com/opsgenie/oec/git" - "github.com/opsgenie/oec/retryer" - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" "io" "io/ioutil" "net/http" @@ -16,6 +11,12 @@ import ( "sync" "testing" "time" + + "github.com/opsgenie/oec/conf" + "github.com/opsgenie/oec/git" + "github.com/opsgenie/oec/retryer" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) var mockConf = &conf.Configuration{ diff --git a/queue/queue_provider.go b/queue/queue_provider.go index f4be0e3a..5d9c2815 100644 --- a/queue/queue_provider.go +++ b/queue/queue_provider.go @@ -1,13 +1,14 @@ package queue import ( + "strings" + "sync" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sqs" - "strings" - "sync" ) const ownerId = "ownerId" diff --git a/queue/queue_provider_test.go b/queue/queue_provider_test.go index df62c285..5c9b7270 100644 --- a/queue/queue_provider_test.go +++ b/queue/queue_provider_test.go @@ -1,15 +1,16 @@ package queue import ( + "strconv" + "sync" + "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/client" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/service/sqs" "github.com/pkg/errors" "github.com/stretchr/testify/assert" - "strconv" - "sync" - "testing" ) func newQueueProviderTest() *OECQueueProvider { diff --git a/queue/worker_pool.go b/queue/worker_pool.go index 865e622b..b7f4bf31 100644 --- a/queue/worker_pool.go +++ b/queue/worker_pool.go @@ -1,13 +1,14 @@ package queue import ( + "sync" + "sync/atomic" + "time" + "github.com/google/uuid" "github.com/opsgenie/oec/conf" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "sync" - "sync/atomic" - "time" ) type WorkerPool interface { diff --git a/queue/worker_pool_test.go b/queue/worker_pool_test.go index 44cf7e41..af0bc3b6 100644 --- a/queue/worker_pool_test.go +++ b/queue/worker_pool_test.go @@ -1,9 +1,6 @@ package queue import ( - "github.com/opsgenie/oec/conf" - "github.com/sirupsen/logrus" - "github.com/stretchr/testify/assert" "io/ioutil" "math/cmplx" "os" @@ -11,6 +8,10 @@ import ( "sync/atomic" "testing" "time" + + "github.com/opsgenie/oec/conf" + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" ) var mockPoolConf = &conf.PoolConf{ @@ -30,7 +31,6 @@ var dummyJob = func() { dummy = cmplx.Conj(dummy) - cmplx.Acos(dummy) dummy = cmplx.Sinh(dummy) - cmplx.Conj(dummy) } - return } func TestMain(m *testing.M) { diff --git a/retryer/retryer.go b/retryer/retryer.go index d590a0a4..1a3d7428 100644 --- a/retryer/retryer.go +++ b/retryer/retryer.go @@ -3,14 +3,15 @@ package retryer import ( "bytes" "fmt" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" "io" "io/ioutil" "math" "net" "net/http" "time" + + "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) const maxRetryCount = 5 diff --git a/retryer/retryer_test.go b/retryer/retryer_test.go index 67c8882a..ef4872f5 100644 --- a/retryer/retryer_test.go +++ b/retryer/retryer_test.go @@ -1,16 +1,17 @@ package retryer import ( - "github.com/stretchr/testify/assert" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestGetWaitTime(t *testing.T) { testCases := []struct { retryCount int - waitTime time.Duration + waitTime time.Duration }{ {0, 100 * time.Millisecond}, {1, 200 * time.Millisecond}, diff --git a/runbook/executor_test.go b/runbook/executor_test.go index f472d0f3..74b7617b 100644 --- a/runbook/executor_test.go +++ b/runbook/executor_test.go @@ -2,11 +2,12 @@ package runbook import ( "bytes" - "github.com/opsgenie/oec/util" - "github.com/stretchr/testify/assert" "os" "runtime" "testing" + + "github.com/opsgenie/oec/util" + "github.com/stretchr/testify/assert" ) const shFileExt = ".sh" @@ -85,7 +86,8 @@ func TestExecuteWithErrorStream(t *testing.T) { } func TestExecuteWithError(t *testing.T) { - if runtime.GOOS == "darwin" { + switch goos := runtime.GOOS; goos { + case "darwin": content := []byte("sacmasapan") tmpFilePath, err := util.CreateTempTestFile(content, shFileExt) defer os.Remove(tmpFilePath) @@ -103,7 +105,7 @@ func TestExecuteWithError(t *testing.T) { assert.Equal(t, "", cmdOutput.String(), "Output stream from executed file was not empty.") assert.Contains(t, cmdErr.String(), "command not found", "Error stream from executed file does not contain err message.") assert.Contains(t, err.(*ExecError).Stderr, cmdErr.String(), "ExecError is not same as cmdErr.") - } else if runtime.GOOS == "windows" { + case "windows": content := []byte("sacmasapan") tmpFilePath, err := util.CreateTempTestFile(content, batFileExt) defer os.Remove(tmpFilePath) @@ -121,7 +123,7 @@ func TestExecuteWithError(t *testing.T) { assert.Contains(t, cmdErr.String(), "not recognized as an internal or external command", "Error stream from executed file does not contain err message.") assert.Contains(t, err.(*ExecError).Stderr, cmdErr.String(), "ExecError is not same as cmdErr.") - } else if runtime.GOOS == "linux" { + case "linux": content := []byte("sacmasapan") tmpFilePath, err := util.CreateTempTestFile(content, shFileExt) defer os.Remove(tmpFilePath) diff --git a/runbook/sender.go b/runbook/sender.go index f385fd09..32ad430e 100644 --- a/runbook/sender.go +++ b/runbook/sender.go @@ -3,11 +3,12 @@ package runbook import ( "bytes" "encoding/json" - "github.com/opsgenie/oec/retryer" - "github.com/pkg/errors" "io/ioutil" "net/http" "strconv" + + "github.com/opsgenie/oec/retryer" + "github.com/pkg/errors" ) const resultPath = "/v2/integrations/oec/actionExecutionResult" diff --git a/runbook/sender_test.go b/runbook/sender_test.go index 9d105786..70295466 100644 --- a/runbook/sender_test.go +++ b/runbook/sender_test.go @@ -2,13 +2,14 @@ package runbook import ( "encoding/json" - "github.com/opsgenie/oec/retryer" - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "net/http/httptest" "testing" + + "github.com/opsgenie/oec/retryer" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestSendResultToOpsGenie(t *testing.T) { diff --git a/util/util.go b/util/util.go index 5b2ed9d7..17b93a69 100644 --- a/util/util.go +++ b/util/util.go @@ -1,12 +1,13 @@ package util import ( - "github.com/sirupsen/logrus" - "gopkg.in/natefinch/lumberjack.v2" "io/ioutil" "os" "path/filepath" "time" + + "github.com/sirupsen/logrus" + "gopkg.in/natefinch/lumberjack.v2" ) func Min(x, y int64) int64 { diff --git a/util/util_test.go b/util/util_test.go index 205fc9b6..49a04667 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -1,9 +1,10 @@ package util import ( - "github.com/stretchr/testify/assert" "os" "testing" + + "github.com/stretchr/testify/assert" ) func TestCreateTempTestScriptFile(t *testing.T) {