From 3ce27743aee326e47954dea9a08b85ea38450bc5 Mon Sep 17 00:00:00 2001 From: Benj Fassbind Date: Thu, 30 Jun 2022 09:30:09 +0200 Subject: [PATCH] Test utils --- utils/utils_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/utils/utils_test.go b/utils/utils_test.go index 65cd6706..953714ca 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -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()) +}