File: export_linux_test.go

package info (click to toggle)
golang-github-canonical-go-efilib 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,836 kB
  • sloc: makefile: 3
file content (61 lines) | stat: -rw-r--r-- 1,077 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
// Copyright 2020 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.

package efi

import (
	"errors"
	"os"

	"golang.org/x/sys/unix"
)

type (
	EfivarfsVarsBackend = efivarfsVarsBackend
	VarFile             = varFile
)

var (
	Defer = errors.New("")
)

func MockOpenVarFile(fn func(string, int, os.FileMode) (VarFile, error)) (restore func()) {
	orig := openVarFile

	openVarFile = func(path string, flags int, perm os.FileMode) (VarFile, error) {
		f, err := fn(path, flags, perm)
		if err == Defer {
			return orig(path, flags, perm)
		}
		return f, err
	}

	return func() {
		openVarFile = orig
	}
}

func MockRemoveVarFile(fn func(string) error) (restore func()) {
	orig := removeVarFile

	removeVarFile = func(path string) error {
		err := fn(path)
		if err == Defer {
			return orig(path)
		}
		return err
	}

	return func() {
		removeVarFile = orig
	}
}

func MockUnixStatfs(fn func(string, *unix.Statfs_t) error) (restore func()) {
	orig := unixStatfs
	unixStatfs = fn
	return func() {
		unixStatfs = orig
	}
}