File: utils_test.go

package info (click to toggle)
aptly 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,928 kB
  • sloc: python: 10,398; sh: 252; makefile: 184
file content (40 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package utils

import (
	"fmt"
	"log"
	"os"
	"testing"

	. "gopkg.in/check.v1"
)

// Launch gocheck tests
func Test(t *testing.T) {
	TestingT(t)
}

type UtilsSuite struct {
	tempfile *os.File
}

var _ = Suite(&UtilsSuite{})

func (s *UtilsSuite) SetUpSuite(c *C) {
	s.tempfile, _ = os.CreateTemp(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) {
	accessible := DirIsAccessible(s.tempfile.Name())
	if accessible == nil {
            c.Fatalf("Test dir should not be accessible: %s", s.tempfile.Name())
        }
	c.Check(accessible.Error(), Equals, fmt.Errorf("'%s' is inaccessible, check access rights", s.tempfile.Name()).Error())
}