File: dir_test.go

package info (click to toggle)
golang-github-hanwen-go-fuse 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,392 kB
  • sloc: cpp: 78; sh: 45; makefile: 16
file content (85 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2023 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fs

import (
	"context"
	"fmt"
	"syscall"
	"testing"

	"github.com/hanwen/go-fuse/v2/fuse"
)

type dirStreamErrorNode struct {
	Inode
}

var _ = (NodeReaddirer)((*dirStreamErrorNode)(nil))

func (n *dirStreamErrorNode) Readdir(ctx context.Context) (DirStream, syscall.Errno) {
	return &errDirStream{}, 0
}

type errDirStream struct {
	num int
}

func (ds *errDirStream) HasNext() bool {
	return ds.num < 2
}

func (ds *errDirStream) Next() (fuse.DirEntry, syscall.Errno) {
	ds.num++
	if ds.num == 1 {
		return fuse.DirEntry{
			Mode: fuse.S_IFREG,
			Name: "first",
			Ino:  2,
		}, 0
	}
	if ds.num == 2 {
		return fuse.DirEntry{
			Mode: fuse.S_IFREG,
			Name: "last",
			Ino:  3,
		}, syscall.EKEYEXPIRED
	}

	panic("boom")
}

func (ds *errDirStream) Close() {

}

func TestDirStreamError(t *testing.T) {
	for _, disableReaddirplus := range []bool{false, true} {
		t.Run(fmt.Sprintf("disableReaddirplus=%v", disableReaddirplus),
			func(t *testing.T) {
				root := &dirStreamErrorNode{}
				opts := Options{}
				opts.DisableReadDirPlus = disableReaddirplus

				mnt, _ := testMount(t, root, &opts)

				ds, errno := NewLoopbackDirStream(mnt)
				if errno != 0 {
					t.Fatalf("NewLoopbackDirStream: %v", errno)
				}
				defer ds.Close()

				if e, errno := ds.Next(); errno != 0 {
					t.Errorf("ds.Next: %v", errno)
				} else if e.Name != "first" {
					t.Errorf("got %q want 'first'", e.Name)
				}

				if _, errno := ds.Next(); errno != syscall.EKEYEXPIRED {
					t.Errorf("got errno %v, want EKEYEXPIRED", errno)
				}
			})
	}
}