Added the 'new' command, which creates a new minecraft server instance
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
23
util/env.go
Normal file
23
util/env.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"os/user"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ResolveTilde(path string) string {
|
||||
usr, _ := user.Current()
|
||||
dir := usr.HomeDir
|
||||
|
||||
if path == "~" {
|
||||
// In case of "~", which won't be caught by the "else if"
|
||||
path = dir
|
||||
} else if strings.HasPrefix(path, "~/") {
|
||||
// Use strings.HasPrefix so we don't match paths like
|
||||
// "/something/~/something/"
|
||||
path = filepath.Join(dir, path[2:])
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
29
util/env_test.go
Normal file
29
util/env_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
// define our test suite struct
|
||||
type EnvTestSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
// the tilde should expand to user's home directory
|
||||
func (s *EnvTestSuite) TestResolveTilde() {
|
||||
resolvedPath := ResolveTilde("~")
|
||||
assert.NotEqual(s.T(), resolvedPath, "~")
|
||||
}
|
||||
|
||||
// ensure the tilde + relative path gets expanded fully
|
||||
func (s *EnvTestSuite) TestResolveTildePath() {
|
||||
resolvedPath := ResolveTilde("~/test")
|
||||
assert.NotEqual(s.T(), resolvedPath, "~/test")
|
||||
}
|
||||
|
||||
// this is needed to run the test suite
|
||||
func TestEnvTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(EnvTestSuite))
|
||||
}
|
||||
Reference in New Issue
Block a user