Skip to content

Commit

Permalink
Lowercasing log and error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofferahl committed Feb 26, 2021
1 parent fb42e45 commit 66503b6
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cmd/centry/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func registerManifestCommands(runtime *Runtime, options *cmd.OptionsSet) {
if err != nil {
context.log.GetLogger().WithFields(logrus.Fields{
"command": cmd.Name,
}).Errorf("Failed to parse script functions. %v", err)
}).Errorf("failed to parse script functions. %v", err)
} else {
for _, fn := range funcs {
fn := fn
Expand Down
6 changes: 3 additions & 3 deletions cmd/centry/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func initFromArgs(runtime *Runtime, inputArgs []string) error {
}

if runtime.file == "" {
return fmt.Errorf("A value must be specified for --centry-file")
return fmt.Errorf("a value must be specified for --centry-file")
}

runtime.events = append(runtime.events, fmt.Sprintf("manifest file path set (path=%s source=%s)", runtime.file, "flag"))
Expand All @@ -129,7 +129,7 @@ func initFromArgs(runtime *Runtime, inputArgs []string) error {
runtime.args = inputArgs[1:]

if runtime.file == "" {
return fmt.Errorf("A value must be specified for --centry-file")
return fmt.Errorf("a value must be specified for --centry-file")
}

runtime.events = append(runtime.events, fmt.Sprintf("manifest file path set (path=%s source=%s)", runtime.file, "flag"))
Expand Down Expand Up @@ -186,7 +186,7 @@ func handleCommandNotFound(runtime *Runtime, c *cli.Context, command string) {
logger := runtime.context.log.GetLogger()
logger.WithFields(logrus.Fields{
"command": command,
}).Warnf("Command not found!")
}).Warnf("command not found!")
c.App.Metadata[metadataExitCode] = 127
}

Expand Down
18 changes: 9 additions & 9 deletions cmd/centry/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestMain(t *testing.T) {
runtime, err := NewRuntime([]string{}, context)
g.Assert(runtime == nil).IsTrue("expected runtime to be nil, %v", runtime)
g.Assert(err != nil).IsTrue("expected error, %v", err)
g.Assert(err.Error()).Eql("Manifest file not found (path=./centry.yaml)")
g.Assert(err.Error()).Eql("manifest file not found (path=./centry.yaml)")
})

g.It("tries to use file specified CENTRY_FILE environment variable", func() {
Expand All @@ -33,7 +33,7 @@ func TestMain(t *testing.T) {
runtime, err := NewRuntime([]string{}, context)
g.Assert(runtime == nil).IsTrue("expected runtime to be nil, %v", runtime)
g.Assert(err != nil).IsTrue("expected error, %v", err)
g.Assert(err.Error()).Eql("Manifest file not found (path=./centry-environment.yaml)")
g.Assert(err.Error()).Eql("manifest file not found (path=./centry-environment.yaml)")
os.Setenv("CENTRY_FILE", "")
})

Expand All @@ -42,31 +42,31 @@ func TestMain(t *testing.T) {
runtime, err := NewRuntime([]string{"--centry-file", "./centry-flag.yaml"}, context)
g.Assert(runtime == nil).IsTrue("expected runtime to be nil, %v", runtime)
g.Assert(err != nil).IsTrue("expected error, %v", err)
g.Assert(err.Error()).Eql("Manifest file not found (path=./centry-flag.yaml)")
g.Assert(err.Error()).Eql("manifest file not found (path=./centry-flag.yaml)")
})

g.It("tries to use file specified by --centry-file= flag", func() {
context := NewContext(CLI, io.Headless())
runtime, err := NewRuntime([]string{"--centry-file=./centry-flag-equals.yaml"}, context)
g.Assert(runtime == nil).IsTrue("expected runtime to be nil, %v", runtime)
g.Assert(err != nil).IsTrue("expected error, %v", err)
g.Assert(err.Error()).Eql("Manifest file not found (path=./centry-flag-equals.yaml)")
g.Assert(err.Error()).Eql("manifest file not found (path=./centry-flag-equals.yaml)")
})

g.It("tries to use file specified by --centry-file= flag even when it contains equal signs", func() {
context := NewContext(CLI, io.Headless())
runtime, err := NewRuntime([]string{"--centry-file=./foo=bar.yaml"}, context)
g.Assert(runtime == nil).IsTrue("expected runtime to be nil, %v", runtime)
g.Assert(err != nil).IsTrue("expected error, %v", err)
g.Assert(err.Error()).Eql("Manifest file not found (path=./foo=bar.yaml)")
g.Assert(err.Error()).Eql("manifest file not found (path=./foo=bar.yaml)")
})

g.It("gives an error when --centry-file flag is missing it's value", func() {
context := NewContext(CLI, io.Headless())
runtime, err := NewRuntime([]string{"--centry-file"}, context)
g.Assert(runtime == nil).IsTrue("expected runtime to be nil, %v", runtime)
g.Assert(err != nil).IsTrue("expected error, %v", err)
g.Assert(err.Error()).Eql("A value must be specified for --centry-file")
g.Assert(err.Error()).Eql("a value must be specified for --centry-file")
})
})
})
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestMain(t *testing.T) {

g.Describe("--centry-quiet", func() {
g.It("should disable logging", func() {
expected := `Changing loglevel to panic (from debug)`
expected := `changing loglevel to panic (from debug)`
out := execWithLogging("--centry-quiet")
test.AssertStringContains(g, out.Stderr, expected)
})
Expand All @@ -275,15 +275,15 @@ func TestMain(t *testing.T) {

g.Describe("--centry-config-log-level=info", func() {
g.It("should change log level to info", func() {
expected := `Changing loglevel to info (from debug)`
expected := `changing loglevel to info (from debug)`
out := execWithLogging("--centry-config-log-level=info")
test.AssertStringContains(g, out.Stderr, expected)
})
})

g.Describe("--centry-config-log-level=error", func() {
g.It("should change log level to error", func() {
expected := `Changing loglevel to error (from debug)`
expected := `changing loglevel to error (from debug)`
out := execWithLogging("--centry-config-log-level=error")
test.AssertStringContains(g, out.Stderr, expected)
})
Expand Down
10 changes: 5 additions & 5 deletions cmd/centry/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ func (sc *ScriptCommand) ToCLICommand() *cli.Command {

// Run builds the source and executes it
func (sc *ScriptCommand) Run(c *cli.Context, args []string) int {
sc.Log.Debugf("Executing command \"%v\"", sc.Function.Name)
sc.Log.Debugf("executing command \"%v\"", sc.Function.Name)

var source string
switch sc.Script.Language() {
case "bash":
source = generateBashSource(c, sc, args)
sc.Log.Debugf("Generated bash source:\n%s\n", source)
sc.Log.Debugf("generated bash source\n%s\n", source)
default:
sc.Log.Errorf("Unsupported script language %s", sc.Script.Language())
sc.Log.Errorf("unsupported script language %s", sc.Script.Language())
return 1
}

Expand All @@ -79,11 +79,11 @@ func (sc *ScriptCommand) Run(c *cli.Context, args []string) int {
}
}

sc.Log.Debugf("Script exited with error, %v", err)
sc.Log.Debugf("script exited with error, %v", err)
return exitCode
}

sc.Log.Debugf("Finished executing command %s...", sc.Function.Name)
sc.Log.Debugf("finished executing command %s...", sc.Function.Name)
return 0
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/centry/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (sc *ServeCommand) ToCLICommand() *cli.Command {

// Run starts an HTTP server and blocks
func (sc *ServeCommand) Run(args []string) int {
sc.Log.Debugf("Serving HTTP api")
sc.Log.Debugf("serving HTTP api")

s := api.NewServer(api.Config{
Log: sc.Log,
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func basicAuthMiddleware(config Config) func(next http.Handler) http.Handler {
config.Log.WithFields(logrus.Fields{
"service": "HTTP-Server",
"middleware": "basic-auth",
}).Debugf("Authentication failed")
}).Debugf("authentication failed")
return
}

config.Log.WithFields(logrus.Fields{
"service": "HTTP-Server",
"middleware": "basic-auth",
}).Debugf("Successfully authenticated")
}).Debugf("successfully authenticated")

next.ServeHTTP(w, r)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/config/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ParseAnnotation(text string) (*Annotation, error) {

kvp := strings.SplitN(keyValueString, "=", 2)
if len(kvp) != 2 {
return nil, fmt.Errorf("Failed to parse annotation! The text \"%s\" is not a valid annotation", text)
return nil, fmt.Errorf("failed to parse annotation! The text \"%s\" is not a valid annotation", text)
}

return &Annotation{
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/config/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func LoadManifest(manifest string) (*Manifest, error) {
mp, _ := filepath.Abs(manifest)

if _, err := os.Stat(mp); os.IsNotExist(err) {
return nil, fmt.Errorf("Manifest file not found (path=%s)", manifest)
return nil, fmt.Errorf("manifest file not found (path=%s)", manifest)
}

bs, err := readManifestFile(mp)
Expand Down Expand Up @@ -109,7 +109,7 @@ func LoadManifest(manifest string) (*Manifest, error) {
func readManifestFile(filename string) ([]byte, error) {
bs, err := ioutil.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("Failed to read manifest file (path=%s). %v", filename, err)
return nil, fmt.Errorf("failed to read manifest file (path=%s). %v", filename, err)
}
return bs, nil
}
Expand All @@ -118,7 +118,7 @@ func parseManifestYaml(bs []byte) (*Manifest, error) {
m := Manifest{}
err := yaml2.Unmarshal(bs, &m)
if err != nil {
return nil, fmt.Errorf("Failed to parse manifest yaml. %v", err)
return nil, fmt.Errorf("failed to parse manifest yaml. %v", err)
}
return &m, nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/config/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestManifest(t *testing.T) {
m, err := LoadManifest("foo")
g.Assert(m == nil).IsTrue("exected manifest to be nil")
g.Assert(err != nil).IsTrue("expected error")
g.Assert(err.Error()).Equal("Manifest file not found (path=foo)")
g.Assert(err.Error()).Equal("manifest file not found (path=foo)")
})
})

Expand All @@ -53,7 +53,7 @@ func TestManifest(t *testing.T) {
bs, err := readManifestFile("foo")
g.Assert(bs == nil).IsTrue("exected byte slice to be nil")
g.Assert(err != nil).IsTrue("expected error")
g.Assert(strings.HasPrefix(err.Error(), "Failed to read manifest file")).IsTrue("expected error message")
g.Assert(strings.HasPrefix(err.Error(), "failed to read manifest file")).IsTrue("expected error message")
})
})

Expand All @@ -68,7 +68,7 @@ func TestManifest(t *testing.T) {
m, err := parseManifestYaml([]byte("invalid yaml"))
g.Assert(m == nil).IsTrue("exected manifest to be nil")
g.Assert(err != nil).IsTrue("expected error")
g.Assert(strings.HasPrefix(err.Error(), "Failed to parse manifest yaml")).IsTrue("expected error message")
g.Assert(strings.HasPrefix(err.Error(), "failed to parse manifest yaml")).IsTrue("expected error message")
})
})

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/log/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func (m *Manager) GetLogger() *logrus.Logger {
func (m *Manager) TrySetLogLevel(level string) {
if !strings.EqualFold(level, m.config.Level) {
logger := m.GetLogger()
logger.Debugf("Changing loglevel to %s (from %s)", level, m.config.Level)
logger.Debugf("changing loglevel to %s (from %s)", level, m.config.Level)
l, _ := logrus.ParseLevel(level)
logger.SetLevel(l)
logger.Debugf("Changed loglevel to %s (from %s)", l, m.config.Level)
logger.Debugf("changed loglevel to %s (from %s)", l, m.config.Level)
m.config.Level = l.String()
}
}
2 changes: 1 addition & 1 deletion internal/pkg/shell/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *BashScript) FunctionAnnotations() ([]*config.Annotation, error) {
if strings.HasPrefix(t, "#") {
a, err := config.ParseAnnotation(strings.TrimLeft(t, "#"))
if err != nil {
s.Log.Debugf("%s", err.Error())
s.Log.Debug(err.Error())
} else if a != nil {
annotations = append(annotations, a)
}
Expand Down

0 comments on commit 66503b6

Please sign in to comment.