Skip to content

Commit

Permalink
tt: fix unit tests
Browse files Browse the repository at this point in the history
Fixed unit tests.
Since /private/var and /var/ in macOS are symlinks, there is no real
difference between them and it should not cause error.
Added macOS support for TestGetVersions.

Follow up #254
Closes #170
  • Loading branch information
better0fdead committed Dec 7, 2022
1 parent 801867b commit f803d85
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 11 deletions.
28 changes: 24 additions & 4 deletions cli/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tarantool/tt/cli/util"
)

const testDirName = "build-test-dir"
Expand All @@ -24,17 +25,26 @@ func TestFillCtx(t *testing.T) {
require.NoError(t, os.Chdir(workDir))
defer os.Chdir(wd)
var buildCtx BuildCtx

osType, _ := util.GetOs()
switch osType {
case util.OsMacos:
workDir = filepath.Join("/private", workDir)
}
appDir := filepath.Join(workDir, "app1")
appDir2 := filepath.Join(workDir, "app2")

require.NoError(t, FillCtx(&buildCtx, []string{"app1"}))
assert.Equal(t, buildCtx.BuildDir, filepath.Join(workDir, "app1"))
assert.Equal(t, buildCtx.BuildDir, appDir)
require.NoError(t, FillCtx(&buildCtx, []string{"./app1"}))
assert.Equal(t, buildCtx.BuildDir, filepath.Join(workDir, "app1"))
assert.Equal(t, buildCtx.BuildDir, appDir)

require.NoError(t, FillCtx(&buildCtx, []string{}))
assert.Equal(t, buildCtx.BuildDir, workDir)

require.EqualError(t, FillCtx(&buildCtx, []string{"app1", "app2"}), "too many args")
require.EqualError(t, FillCtx(&buildCtx, []string{"app2"}),
fmt.Sprintf("stat %s: no such file or directory", filepath.Join(workDir, "app2")))
fmt.Sprintf("stat %s: no such file or directory", appDir2))

require.NoError(t, FillCtx(&buildCtx, []string{filepath.Join(workDir, "app1")}))
assert.Equal(t, buildCtx.BuildDir, filepath.Join(workDir, "app1"))
Expand Down Expand Up @@ -62,8 +72,18 @@ func TestFillCtxAppPathIsFile(t *testing.T) {
require.NoError(t, os.Chdir(workDir))
defer os.Chdir(wd)
var buildCtx BuildCtx

osType, _ := util.GetOs()
appDir := ""
switch osType {
case util.OsMacos:
appDir = filepath.Join("/private", workDir, "app1")
case util.OsLinux:
appDir = filepath.Join(workDir, "app1")
}

require.EqualError(t, FillCtx(&buildCtx, []string{"app1"}),
fmt.Sprintf("%s is not a directory", filepath.Join(workDir, "app1")))
fmt.Sprintf("%s is not a directory", appDir))
}

func TestFillCtxMultipleArgs(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion cli/configure/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ func TestGetConfigPath(t *testing.T) {
require.NoError(t, os.Remove(filepath.Join(tempDir, "a", "tarantool.yaml")))

configName, err = getConfigPath(ConfigName)
assert.Equal(t, filepath.Join(tempDir, "a", "tarantool.yml"), configName)

osType, _ := util.GetOs()
prefix := ""
switch osType {
case util.OsMacos:
prefix = "/private"
}

assert.Equal(t, filepath.Join(prefix, tempDir, "a", "tarantool.yml"), configName)
assert.NoError(t, err)
}
35 changes: 31 additions & 4 deletions cli/install_ee/install_ee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/tarantool/tt/cli/util"
"github.com/tarantool/tt/cli/version"
)

Expand All @@ -30,9 +31,34 @@ func TestGetVersions(t *testing.T) {
err: fmt.Errorf("no packages for this OS"),
}

inputData1 := []byte(`<a href="/enterprise/tarantool-enterprise-bundle-` +
`1.10.10-52-g0df29b137-r419.tar.gz">tarantool-enterprise-bundle-1.10.10-` +
`52-g0df29b137-r419.tar.gz</a> 2021-08-18 ` +
arch, err := util.GetArch()
assert.Nil(err)

osType, err := util.GetOs()
assert.Nil(err)
inputData1 := []byte(``)
osName := ""
switch osType {
case util.OsLinux:
// Bundles without specifying the architecture are all x86_64.
if arch == "x86_64" {
arch = ""
}
case util.OsMacos:
// Bundles without specifying the architecture are all x86_64.
if arch == "x86_64" {
osName = "-macosx-"
arch = "x86_64"
} else {
osName = "-macosx-"
}
}

inputData1 = []byte(`<a href="/enterprise/tarantool-enterprise-bundle-` +
`1.10.10-52-g0df29b137-r419` + osName + arch +
`.tar.gz">tarantool-enterprise-bundle-1.10.10-` +
`52-g0df29b137-r419` + osName + arch + `.tar.gz</a>` +
` 2021-08-18 ` +
`15:56:04 260136444`)

testCases[getVersionsInputValue{data: &inputData1}] =
Expand All @@ -47,7 +73,8 @@ func TestGetVersions(t *testing.T) {
Release: version.Release{Type: version.TypeRelease},
Hash: "g0df29b137",
Str: "1.10.10-52-g0df29b137-r419",
Tarball: "tarantool-enterprise-bundle-1.10.10-52-g0df29b137-r419.tar.gz",
Tarball: "tarantool-enterprise-bundle-1.10.10-52-g0df29b137-r419" +
osName + arch + ".tar.gz",
},
},
err: nil,
Expand Down
10 changes: 8 additions & 2 deletions cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,14 @@ func ExecuteCommandStdin(program string, isVerbose bool, logFile *os.File, workD
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} else {
cmd.Stdout = logFile
cmd.Stderr = logFile
if logFile != nil {
cmd.Stdout = logFile
cmd.Stderr = logFile
} else {
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
}

}
if workDir == "" {
workDir, _ = os.Getwd()
Expand Down

0 comments on commit f803d85

Please sign in to comment.