Added tests
This commit is contained in:
		
							parent
							
								
									85f19a6074
								
							
						
					
					
						commit
						3dca802a22
					
				|  | @ -1,6 +1,9 @@ | ||||||
| package util | package util | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"os" | ||||||
|  | 	"os/user" | ||||||
|  | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
| 	"github.com/stretchr/testify/assert" | 	"github.com/stretchr/testify/assert" | ||||||
|  | @ -8,22 +11,58 @@ import ( | ||||||
| 
 | 
 | ||||||
| func TestFileExist(t *testing.T) { | func TestFileExist(t *testing.T) { | ||||||
| 	assert.True(t, FileExists("utils.go")) | 	assert.True(t, FileExists("utils.go")) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestFileExistNot(t *testing.T) { | ||||||
| 	assert.True(t, !FileExists("Utils2.go")) | 	assert.True(t, !FileExists("Utils2.go")) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestJoiningSlash(t *testing.T) { | func TestGlobalConfigurationDirectory(t *testing.T) { | ||||||
| 	assert.Equal(t, "http://my.tld/bla/blub", JoiningSlash("http://my.tld", "bla", "blub")) | 	appFolder := GetGlobalConfigurationDirectory("myapp") | ||||||
| 	assert.Equal(t, "http://my.tld/bla/blub", JoiningSlash("http://my.tld/", "bla", "blub")) | 	assert.NotEmpty(t, appFolder) | ||||||
| 	assert.Equal(t, "http://my.tld/bla/blub", JoiningSlash("http://my.tld", "bla/", "blub")) |  | ||||||
| 	assert.Equal(t, "http://my.tld/docs/bla/blub", JoiningSlash("http://my.tld/docs", "bla/", "blub")) |  | ||||||
| 	assert.Equal(t, "http://my.tld/docs/bla/blub", JoiningSlash("http://my.tld/docs/", "bla/", "blub")) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Can run only as admin within windows or linux | func TestJoiningSlash1(t *testing.T) { | ||||||
|  | 	actual := JoiningSlash("http://my.tld/docs/", "bla/", "blub/") | ||||||
|  | 	expected := "http://my.tld/docs/bla/blub/" | ||||||
|  | 	assert.Equal(t, expected, actual) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestJoiningSlash2(t *testing.T) { | ||||||
|  | 	actual := JoiningSlash("http://my.tld", "bla", "blub") | ||||||
|  | 	assert.Equal(t, "http://my.tld/bla/blub", actual) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestJoiningSlash3(t *testing.T) { | ||||||
|  | 	actual := JoiningSlash("http://my.tld/", "bla", "blub") | ||||||
|  | 	assert.Equal(t, "http://my.tld/bla/blub", actual) | ||||||
|  | } | ||||||
|  | func TestJoiningSlash4(t *testing.T) { | ||||||
|  | 	actual := JoiningSlash("http://my.tld", "bla/", "blub") | ||||||
|  | 	assert.Equal(t, "http://my.tld/bla/blub", actual) | ||||||
|  | } | ||||||
|  | func TestJoiningSlash5(t *testing.T) { | ||||||
|  | 	actual := JoiningSlash("http://my.tld/docs", "bla/", "blub") | ||||||
|  | 	expected := "http://my.tld/docs/bla/blub" | ||||||
|  | 	assert.Equal(t, expected, actual) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestJoiningSlash6(t *testing.T) { | ||||||
|  | 	actual := JoiningSlash("http://my.tld/docs/", "bla/", "blub") | ||||||
|  | 	expected := "http://my.tld/docs/bla/blub" | ||||||
|  | 	assert.Equal(t, expected, actual) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  | Can run only as admin within windows or linux | ||||||
|  | e.g. sudo TESTASSUDO=yes /usr/local/go/bin/go test -timeout 30s -run ^TestIsSuperUser$ | ||||||
|  | */ | ||||||
| func TestIsSuperUser(t *testing.T) { | func TestIsSuperUser(t *testing.T) { | ||||||
|  | 	if !strings.EqualFold(os.Getenv("TESTASSUDO"), "yes") { | ||||||
|  | 		t.Skip("Skipping in normal tests") | ||||||
|  | 	} | ||||||
| 	cuser, err := user.Current() | 	cuser, err := user.Current() | ||||||
| 	assert.Nil(t, err) | 	assert.Nil(t, err) | ||||||
| 	assert.NotNil(t, cuser) | 	assert.NotNil(t, cuser) | ||||||
| 	assert.True(t, IsSuperUser()) | 	assert.True(t, IsSuperUser()) | ||||||
| } | } | ||||||
| */ |  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue