feat: add tests

This commit is contained in:
Denis 2018-03-08 16:37:38 +05:00
parent a63fd9d570
commit 4aeef04369
2 changed files with 26 additions and 2 deletions

View File

@ -125,7 +125,7 @@ func AddInventory(w http.ResponseWriter, r *http.Request) {
mulekick.WriteJSON(w, http.StatusCreated, inv)
}
func isValidInventoryPath(path string) bool {
func IsValidInventoryPath(path string) bool {
if currentPath, err := filepath.Abs("./"); err != nil {
return false
} else if absPath, err := filepath.Abs(path); err != nil {
@ -157,7 +157,7 @@ func UpdateInventory(w http.ResponseWriter, r *http.Request) {
case "static":
break
case "file":
if !isValidInventoryPath(inventory.Inventory) {
if !IsValidInventoryPath(inventory.Inventory) {
panic("Invalid inventory path")
}
break

24
tests/inventory_test.go Normal file
View File

@ -0,0 +1,24 @@
package tests
import (
"testing"
"path/filepath"
. "gopkg.in/check.v1"
"github.com/ansible-semaphore/semaphore/api/projects"
)
func Test(t *testing.T) { TestingT(t) }
type MySuite struct{}
var _ = Suite(&MySuite{})
func (s *MySuite) TestIsValidInventoryPath(c *C) {
isValid := projects.IsValidInventoryPath("")
c.Assert(isValid, Equals, true)
}
func (s *MySuite) TestFilePathMatch(c *C) {
matched, _ := filepath.Match("test.*", "test.txt")
c.Assert(matched, Equals, true)
}