diff --git a/command/agent/fs_endpoint.go b/command/agent/fs_endpoint.go index ab5048107..ccc552181 100644 --- a/command/agent/fs_endpoint.go +++ b/command/agent/fs_endpoint.go @@ -311,10 +311,11 @@ func (s *StreamFramer) run() { // Store any error and mark it as not running var err error defer func() { - s.l.Lock() - s.Err = err close(s.exitCh) close(s.outbound) + + s.l.Lock() + s.Err = err s.running = false s.l.Unlock() }() @@ -338,8 +339,11 @@ func (s *StreamFramer) run() { // Read the data for the frame, and send it s.f.Data = s.readData() - s.outbound <- s.f - s.f = nil + select { + case s.outbound <- s.f: + s.f = nil + default: + } s.l.Unlock() case <-s.heartbeat.C: // Send a heartbeat frame diff --git a/command/fs.go b/command/fs.go index 66bce5bb6..df1bbf91d 100644 --- a/command/fs.go +++ b/command/fs.go @@ -50,7 +50,7 @@ FS Specific Options: Show full information. -job - Use a random allocation from a specified job-id. + Use a random allocation from the specified job ID. -stat Show file stat information instead of displaying the file, or listing the directory. diff --git a/command/logs.go b/command/logs.go index e5aa6297a..6f105202c 100644 --- a/command/logs.go +++ b/command/logs.go @@ -24,7 +24,7 @@ Usage: nomad logs [options] General Options: - ` + generalOptionsUsage() + ` + ` + generalOptionsUsage() + ` Logs Specific Options: @@ -32,7 +32,7 @@ Logs Specific Options: Show full information. -job - Use a random allocation from a specified job-id. + Use a random allocation from the specified job ID. -f Causes the output to not stop when the end of the logs are reached, but @@ -60,7 +60,7 @@ func (l *LogsCommand) Run(args []string) int { var verbose, job, tail, stderr, follow bool var numLines, numBytes int64 - flags := l.Meta.FlagSet("logs-list", FlagSetClient) + flags := l.Meta.FlagSet("logs", FlagSetClient) flags.Usage = func() { l.Ui.Output(l.Help()) } flags.BoolVar(&verbose, "verbose", false, "") flags.BoolVar(&job, "job", false, "") @@ -75,13 +75,17 @@ func (l *LogsCommand) Run(args []string) int { } args = flags.Args() - if len(args) < 1 { + if numArgs := len(args); numArgs < 1 { if job { - l.Ui.Error("Job ID required") + l.Ui.Error("Job ID required. See help:\n") } else { - l.Ui.Error("Allocation ID required") + l.Ui.Error("Allocation ID required. See help:\n") } + l.Ui.Error(l.Help()) + return 1 + } else if numArgs > 2 { + l.Ui.Error(l.Help()) return 1 } diff --git a/command/logs_test.go b/command/logs_test.go new file mode 100644 index 000000000..2400b6302 --- /dev/null +++ b/command/logs_test.go @@ -0,0 +1,65 @@ +package command + +import ( + "strings" + "testing" + + "github.com/mitchellh/cli" +) + +func TestLogsCommand_Implements(t *testing.T) { + var _ cli.Command = &LogsCommand{} +} + +func TestLogsCommand_Fails(t *testing.T) { + srv, _, url := testServer(t, nil) + defer srv.Stop() + + ui := new(cli.MockUi) + cmd := &LogsCommand{Meta: Meta{Ui: ui}} + + // Fails on misuse + if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { + t.Fatalf("expected exit code 1, got: %d", code) + } + if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + t.Fatalf("expected help output, got: %s", out) + } + ui.ErrorWriter.Reset() + + // Fails on connection failure + if code := cmd.Run([]string{"-address=nope", "foobar"}); code != 1 { + t.Fatalf("expected exit code 1, got: %d", code) + } + if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying allocation") { + t.Fatalf("expected failed query error, got: %s", out) + } + ui.ErrorWriter.Reset() + + // Fails on missing alloc + if code := cmd.Run([]string{"-address=" + url, "26470238-5CF2-438F-8772-DC67CFB0705C"}); code != 1 { + t.Fatalf("expected exit 1, got: %d", code) + } + if out := ui.ErrorWriter.String(); !strings.Contains(out, "No allocation(s) with prefix or id") { + t.Fatalf("expected not found error, got: %s", out) + } + ui.ErrorWriter.Reset() + + // Fail on identifier with too few characters + if code := cmd.Run([]string{"-address=" + url, "2"}); code != 1 { + t.Fatalf("expected exit 1, got: %d", code) + } + if out := ui.ErrorWriter.String(); !strings.Contains(out, "must contain at least two characters.") { + t.Fatalf("expected too few characters error, got: %s", out) + } + ui.ErrorWriter.Reset() + + // Identifiers with uneven length should produce a query result + if code := cmd.Run([]string{"-address=" + url, "123"}); code != 1 { + t.Fatalf("expected exit 1, got: %d", code) + } + if out := ui.ErrorWriter.String(); !strings.Contains(out, "No allocation(s) with prefix or id") { + t.Fatalf("expected not found error, got: %s", out) + } + +}