Test utils

This commit is contained in:
Benj Fassbind
2022-06-30 09:30:09 +02:00
parent c9f5763a70
commit 3ce27743ae

View File

@@ -1,6 +1,10 @@
package utils
import (
"fmt"
"io/ioutil"
"log"
"os"
"testing"
. "gopkg.in/check.v1"
@@ -10,3 +14,24 @@ import (
func Test(t *testing.T) {
TestingT(t)
}
type UtilsSuite struct {
tempfile *os.File
}
var _ = Suite(&UtilsSuite{})
func (s *UtilsSuite) SetUpSuite(c *C) {
s.tempfile, _ = ioutil.TempFile(c.MkDir(), "aptly-test-inaccessible")
if err := os.Chmod(s.tempfile.Name(), 0000); err != nil {
log.Fatalln(err)
}
}
func (s *UtilsSuite) TestDirIsAccessibleNotExist(c *C) {
c.Check(DirIsAccessible("does/not/exist.invalid"), Equals, nil)
}
func (s *UtilsSuite) TestDirIsAccessibleNotAccessible(c *C) {
c.Check(DirIsAccessible(s.tempfile.Name()).Error(), Equals, fmt.Errorf("'%s' is inaccessible, check access rights", s.tempfile.Name()).Error())
}