From 34ad854a3306155dd015adc6e8a971b7ba2f707d Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 17 Aug 2017 18:41:08 -0300 Subject: [PATCH] improved logs --- pipeline/fpm/fpm.go | 2 +- pipeline/snapcraft/snapcraft.go | 16 ++++++++++++---- pipeline/snapcraft/snapcraft_test.go | 14 +++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pipeline/fpm/fpm.go b/pipeline/fpm/fpm.go index 8fc5ce3f7..ddd555827 100644 --- a/pipeline/fpm/fpm.go +++ b/pipeline/fpm/fpm.go @@ -27,7 +27,7 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { if len(ctx.Config.FPM.Formats) == 0 { - log.Info("no output formats configured, skipping") + log.Warn("skipping because no output formats configured") return nil } _, err := exec.LookPath("fpm") diff --git a/pipeline/snapcraft/snapcraft.go b/pipeline/snapcraft/snapcraft.go index 7c4b84658..68d202ac8 100644 --- a/pipeline/snapcraft/snapcraft.go +++ b/pipeline/snapcraft/snapcraft.go @@ -19,6 +19,12 @@ import ( // ErrNoSnapcraft is shown when snapcraft cannot be found in $PATH var ErrNoSnapcraft = errors.New("snapcraft not present in $PATH") +// ErrNoDescription is shown when no description provided +var ErrNoDescription = errors.New("no description provided for snapcraft") + +// ErrNoSummary is shown when no summary provided +var ErrNoSummary = errors.New("no summary provided for snapcraft") + // SnapcraftMetadata to generate the snap package type SnapcraftMetadata struct { Name string @@ -48,13 +54,15 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - if ctx.Config.Snapcraft.Summary == "" { - log.Error("no snapcraft summary defined, skipping") + if ctx.Config.Snapcraft.Summary == "" && ctx.Config.Snapcraft.Description == "" { + log.Warn("skipping because no summary nor description were provided") return nil } + if ctx.Config.Snapcraft.Summary == "" { + return ErrNoSummary + } if ctx.Config.Snapcraft.Description == "" { - log.Error("no snapcraft description defined, skipping") - return nil + return ErrNoDescription } _, err := exec.LookPath("snapcraft") if err != nil { diff --git a/pipeline/snapcraft/snapcraft_test.go b/pipeline/snapcraft/snapcraft_test.go index ea990f300..f57beb39a 100644 --- a/pipeline/snapcraft/snapcraft_test.go +++ b/pipeline/snapcraft/snapcraft_test.go @@ -1,6 +1,7 @@ package snapcraft import ( + "fmt" "io/ioutil" "os" "path/filepath" @@ -17,24 +18,23 @@ func TestDescription(t *testing.T) { } func TestRunPipeMissingInfo(t *testing.T) { - for name, snap := range map[string]config.Snapcraft{ - "missing summary": { + for eerr, snap := range map[error]config.Snapcraft{ + ErrNoSummary: { Description: "dummy desc", }, - "missing description": { + ErrNoDescription: { Summary: "dummy summary", }, + nil: {}, // should skip instead of error } { - t.Run(name, func(t *testing.T) { + t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) { var assert = assert.New(t) var ctx = &context.Context{ Config: config.Project{ Snapcraft: snap, }, } - // FIXME: there is no way to tell here if the pipe actually ran - // or if it was indeed skipped. - assert.NoError(Pipe{}.Run(ctx)) + assert.Equal(eerr, Pipe{}.Run(ctx)) }) } }