Permalink
Browse files

fix #24: add progress bar github.com/briandowns/spinner

  • Loading branch information...
kamilsk committed Apr 29, 2018
1 parent f3b074d commit a9be82d8c06f4a272418db54286ba4ed06c2a581

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -18,6 +18,10 @@
name = "github.com/stretchr/testify"
version = "^1.2.0"

[[constraint]]
name = "github.com/briandowns/spinner"
version = "^1.0.0"

[prune]
go-tests = true
unused-packages = true
@@ -2,9 +2,8 @@ package cmd

import (
"bytes"
"testing"

"fmt"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
@@ -38,8 +37,18 @@ func TestURLs(t *testing.T) {
urlsCmd.SetOutput(buf)
defer closer()
defer urlsCmd.SetOutput(nil)
assert.NoError(t, urlsCmd.RunE(urlsCmd, []string{site.URL + "/"}))
assert.Contains(t, buf.String(), fmt.Sprintf("[200] %s/", site.URL))
{
buf.Reset()
assert.NoError(t, urlsCmd.RunE(urlsCmd, []string{site.URL + "/"}))
assert.Contains(t, buf.String(), fmt.Sprintf("[200] %s/", site.URL))
}
{
buf.Reset()
verbose := urlsCmd.Flag("verbose")
verbose.Value.Set("true")
assert.NoError(t, urlsCmd.RunE(urlsCmd, []string{site.URL + "/"}))
verbose.Value.Set(verbose.DefValue)
}
}

func Test_client(t *testing.T) {
@@ -1,6 +1,9 @@
package cmd

import (
"time"

"github.com/briandowns/spinner"
"github.com/kamilsk/check/http/availability"
"github.com/spf13/cobra"
)
@@ -10,23 +13,32 @@ var urlsCmd = &cobra.Command{
Short: "Check all internal URLs on availability",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var spin = func() func() { return func() {} }
verbose := asBool(cmd.Flag("verbose").Value)
if !verbose {
spin = func() func() {
s := spinner.New(spinner.CharSets[34], 100*time.Millisecond)
s.Writer = cmd.OutOrStderr()
s.Start()
return s.Stop
}
}
stop := spin()
report := availability.NewReport(
availability.CrawlerForSites(availability.CrawlerColly(
availability.CrawlerConfig{
UserAgent: client(cmd),
Verbose: verbose,
Output: cmd.OutOrStderr(),
},
)),
).
For(args).
Fill()
stop()
return availability.
NewPrinter(
availability.OutputForPrinting(cmd.OutOrStdout()),
).
For(
availability.NewReport(
availability.CrawlerForSites(availability.CrawlerColly(
availability.CrawlerConfig{
UserAgent: client(cmd),
Verbose: asBool(cmd.Flag("verbose").Value),
Output: cmd.OutOrStderr(),
},
)),
).
For(args).
Fill(),
).
NewPrinter(availability.OutputForPrinting(cmd.OutOrStdout())).
For(report).
Print()
},
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit a9be82d

Please sign in to comment.