summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-tools-common/failpoint/failpoint.go
blob: c7140f6a8f10028edf17d5a7e016a3a969fa7383 (plain)
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
// Copyright (C) MongoDB, Inc. 2014-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

// +build failpoints

// Package failpoint implements triggers for custom debugging behavoir
package failpoint

import (
	"strings"
)

var values map[string]string

func init() {
	values = make(map[string]string)
}

// ParseFailpoints registers a comma-separated list of failpoint=value pairs
func ParseFailpoints(arg string) {
	args := strings.Split(arg, ",")
	for _, fp := range args {
		if sep := strings.Index(fp, "="); sep != -1 {
			key := fp[:sep]
			val := fp[sep+1:]
			values[key] = val
			continue
		}
		values[fp] = ""
	}
}

// Get returns the value of the given failpoint and true, if it exists, and
// false otherwise
func Get(fp string) (string, bool) {
	val, ok := values[fp]
	return val, ok
}

// Enabled returns true iff the given failpoint has been turned on
func Enabled(fp string) bool {
	_, ok := Get(fp)
	return ok
}