-
Notifications
You must be signed in to change notification settings - Fork 8
/
scribe.go
91 lines (78 loc) · 2.71 KB
/
scribe.go
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
86
87
88
89
90
91
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor:
// - Aaron Meihm ameihm@mozilla.com
// Package scribe implements the Mozilla scribe host policy evaluator.
package scribe
import (
"fmt"
"io"
)
type runtime struct {
debugging bool
debugWriter io.Writer
excall func(TestResult)
testHooks bool
fileLocator func(string, bool, string, int) ([]string, error)
}
// Version is the scribe library version
const Version = "0.5"
var sRuntime runtime
func (r *runtime) initialize() {
}
func init() {
sRuntime.initialize()
}
// Bootstrap the scribe library. This function is currently not used but code
// should call this function before any other functions in the library. An
// error is returned if one occurs.
//
// Applications should call this as it may be mandatory in the future to do
// more explicit initialization of the library outside of init().
func Bootstrap() (err error) {
return err
}
// ExpectedCallback can be used to set a callback function for test results.
//
// Set an expected result callback. f should be a function that takes a TestResult
// type as an argument. When this is set, if the result of a test does not
// match the value set in "expectedresult" for the test, the function is
// immediately called with the applicable TestResult as an argument.
func ExpectedCallback(f func(TestResult)) {
sRuntime.excall = f
}
// InstallFileLocator installs alternate file walking functions.
//
// Install an alternate file location function. This overrides use of the
// SimpleFileLocator locate() function, and allows specification of an
// alternate function to use for locating candidate files on the filesystem.
//
// This function is primarily used within the scribe mig module to make use
// of the file module traversal function.
func InstallFileLocator(f func(string, bool, string, int) ([]string, error)) {
sRuntime.fileLocator = f
}
// TestHooks enables or disables testing hooks in the library.
//
// Enable or disable test hooks. If test hooks are enabled, certain functions
// such as requesting package data from the host system are bypassed in favor
// of test tables.
func TestHooks(f bool) {
sRuntime.testHooks = f
}
func debugPrint(s string, args ...interface{}) {
if !sRuntime.debugging {
return
}
buf := fmt.Sprintf(s, args...)
fmt.Fprintf(sRuntime.debugWriter, "[scribe] %v", buf)
}
// SetDebug enables or disables debugging. If debugging is enabled, output is written
// to the io.Writer specified by w.
func SetDebug(f bool, w io.Writer) {
sRuntime.debugging = f
sRuntime.debugWriter = w
debugPrint("debugging enabled\n")
}