mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
feat: add tests
This commit is contained in:
parent
a63fd9d570
commit
4aeef04369
@ -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
24
tests/inventory_test.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user