Skip to content

Commit

Permalink
fix windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Feb 28, 2024
1 parent cff6a99 commit 44d7942
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions tsuru/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/tsuru/tsuru/cmd"
"github.com/tsuru/tsuru/cmd/cmdtest"
"github.com/tsuru/tsuru/fs/fstest"
"github.com/tsuru/tsuru/types/auth"
"gopkg.in/check.v1"
)

Expand Down Expand Up @@ -182,3 +183,8 @@ func (s *S) TestNativeLoginWithTsuruToken(c *check.C) {
c.Assert(err, check.NotNil)
c.Assert(err.Error(), check.Equals, "this command can't run with $TSURU_TOKEN environment variable set. Did you forget to unset?")
}

func (s *S) TestPort(c *check.C) {
c.Assert(":0", check.Equals, port(&auth.SchemeInfo{}))
c.Assert(":4242", check.Equals, port(&auth.SchemeInfo{Data: auth.SchemeData{Port: "4242"}}))
}
4 changes: 4 additions & 0 deletions tsuru/auth/open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"runtime"
"strings"

"github.com/tsuru/tsuru/exec/exectest"
"gopkg.in/check.v1"
Expand All @@ -18,6 +19,9 @@ func (s *S) TestOpen(c *check.C) {
c.Assert(err, check.IsNil)
if runtime.GOOS == "linux" {
c.Assert(fexec.ExecutedCmd("xdg-open", []string{url}), check.Equals, true)
} else if runtime.GOOS == "windows" {
url = strings.Replace(url, "&", "^&", -1)
c.Assert(fexec.ExecutedCmd("cmd", []string{"/c", "start", "", url}), check.Equals, true)
} else {
c.Assert(fexec.ExecutedCmd("open", []string{url}), check.Equals, true)
}
Expand Down
10 changes: 6 additions & 4 deletions tsuru/config/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bytes"
"io"
"os"
"path"
"runtime"
"strings"

"github.com/tsuru/tsuru/cmd"
Expand All @@ -17,7 +17,7 @@ import (
)

func readRecordedTarget(fs *fstest.RecordingFs) string {
filePath := path.Join(os.ExpandEnv("${HOME}"), ".tsuru", "target")
filePath := JoinWithUserDir(".tsuru", "target")
fil, _ := fs.Open(filePath)
b, _ := io.ReadAll(fil)
return string(b)
Expand All @@ -32,8 +32,10 @@ func (s *S) TestWriteTarget(c *check.C) {
os.Unsetenv("TSURU_TARGET")
err := WriteTarget("http://tsuru.globo.com")
c.Assert(err, check.IsNil)
filePath := path.Join(os.ExpandEnv("${HOME}"), ".tsuru", "target")
c.Assert(rfs.HasAction("openfile "+filePath+" with mode 0600"), check.Equals, true)
filePath := JoinWithUserDir(".tsuru", "target")
if runtime.GOOS != "windows" {
c.Assert(rfs.HasAction("openfile "+filePath+" with mode 0600"), check.Equals, true)
}
c.Assert(readRecordedTarget(rfs), check.Equals, "http://tsuru.globo.com")
}

Expand Down
5 changes: 3 additions & 2 deletions tsuru/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ func (s *S) TestVersionAPIInvalidURL(c *check.C) {
defer os.Unsetenv("TSURU_TARGET")
err := command.Run(&context)
c.Assert(err, check.IsNil)
c.Assert(context.Stdout.(*bytes.Buffer).String(),
check.Equals, "Client version: dev.\nUnable to retrieve server version: Get \"http://notvalid.test/1.0/info\": dial tcp: lookup notvalid.test: no such host")

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.*")
}

0 comments on commit 44d7942

Please sign in to comment.