Skip to content

Commit

Permalink
version: throw error responsible to detect a session expired
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Mar 19, 2024
1 parent 888c138 commit 1249d68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tsuru/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"

"github.com/ajg/form"
"github.com/pkg/errors"
"github.com/tsuru/tsuru-client/tsuru/admin"
"github.com/tsuru/tsuru-client/tsuru/auth"
"github.com/tsuru/tsuru-client/tsuru/client"
Expand Down Expand Up @@ -375,8 +376,7 @@ func apiVersionString() (string, error) {

resp, err := tsuruHTTP.AuthenticatedClient.Do(req)
if err != nil {
// if we return the error, stdout won't flush until the prompt
return fmt.Sprintf("Unable to retrieve server version: %v", err), nil
return "", errors.Wrap(err, "Unable to retrieve server version")
}

body, err := io.ReadAll(resp.Body)
Expand Down
12 changes: 7 additions & 5 deletions tsuru/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
"net"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -19,6 +20,7 @@ import (
"github.com/tsuru/tsuru-client/tsuru/admin"
"github.com/tsuru/tsuru-client/tsuru/client"
"github.com/tsuru/tsuru-client/tsuru/config"
tsuruHTTP "github.com/tsuru/tsuru-client/tsuru/http"
"github.com/tsuru/tsuru/cmd"
"github.com/tsuru/tsuru/exec/exectest"
)
Expand Down Expand Up @@ -548,8 +550,7 @@ func (s *S) TestVersion(c *check.C) {
Args: []string{},
Stdout: &bytes.Buffer{},
}
err := command.Run(&context)
c.Assert(err, check.IsNil)
command.Run(&context)
c.Assert(context.Stdout.(*bytes.Buffer).String(), check.Matches, "Client version: dev.\n.*")
}

Expand Down Expand Up @@ -597,8 +598,9 @@ func (s *S) TestVersionAPIInvalidURL(c *check.C) {
os.Setenv("TSURU_TARGET", URL)
defer os.Unsetenv("TSURU_TARGET")
err := command.Run(&context)
c.Assert(err, check.IsNil)
c.Assert(tsuruHTTP.UnwrapErr(err), check.FitsTypeOf, &net.DNSError{})

stdout := context.Stdout.(*bytes.Buffer).String()

output := context.Stdout.(*bytes.Buffer).String()
c.Assert(output, check.Matches, "Client version: dev.\nUnable to retrieve server version: Get \"http://notvalid.test/1.0/info\": dial tcp: lookup notvalid.test.*")
c.Assert(stdout, check.Matches, "Client version: dev.\n")
}

0 comments on commit 1249d68

Please sign in to comment.