46 lines
871 B
Go
46 lines
871 B
Go
package fixtures
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetProjectRoot(t *testing.T) {
|
|
t.Run("default", func(t *testing.T) {
|
|
root := getProjectRoot()
|
|
assert.True(t, doesFileExist(filepath.Join(root, "go.sum")))
|
|
})
|
|
|
|
t.Run("subdir", func(t *testing.T) {
|
|
root1 := getProjectRoot()
|
|
err := os.Chdir(filepath.Join(root1, "src/server"))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
root := getProjectRoot()
|
|
assert.True(t, doesFileExist(filepath.Join(root, "go.sum")))
|
|
})
|
|
}
|
|
|
|
func TestCdProjectRoot(t *testing.T) {
|
|
CdProjectRoot()
|
|
err := os.Chdir("src/server")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
CdProjectRoot()
|
|
assert.True(t, doesFileExist("go.sum"))
|
|
}
|
|
|
|
func TestResetEnv(t *testing.T) {
|
|
os.Setenv("TSGRAINWEB_PORT", "8001")
|
|
|
|
ResetEnv()
|
|
|
|
_, exists := os.LookupEnv("TSGRAINWEB_PORT")
|
|
assert.False(t, exists)
|
|
}
|