This file is indexed.

/usr/share/gocode/src/github.com/bugsnag/bugsnag-go/configuration_test.go is in golang-github-bugsnag-bugsnag-go-dev 1.0.5+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
package bugsnag

import (
	"log"
	"os"
	"testing"

	"github.com/juju/loggo"
)

func TestNotifyReleaseStages(t *testing.T) {

	var testCases = []struct {
		stage      string
		configured []string
		notify     bool
		msg        string
	}{
		{
			stage:  "production",
			notify: true,
			msg:    "Should notify in all release stages by default",
		},
		{
			stage:      "production",
			configured: []string{"development", "production"},
			notify:     true,
			msg:        "Failed to notify in configured release stage",
		},
		{
			stage:      "staging",
			configured: []string{"development", "production"},
			notify:     false,
			msg:        "Failed to prevent notification in excluded release stage",
		},
	}

	for _, testCase := range testCases {
		Configure(Configuration{ReleaseStage: testCase.stage, NotifyReleaseStages: testCase.configured})

		if Config.notifyInReleaseStage() != testCase.notify {
			t.Error(testCase.msg)
		}
	}
}

func TestProjectPackages(t *testing.T) {
	Configure(Configuration{ProjectPackages: []string{"main", "github.com/ConradIrwin/*"}})
	if !Config.isProjectPackage("main") {
		t.Error("literal project package doesn't work")
	}
	if !Config.isProjectPackage("github.com/ConradIrwin/foo") {
		t.Error("wildcard project package doesn't work")
	}
	if Config.isProjectPackage("runtime") {
		t.Error("wrong packges being marked in project")
	}
	if Config.isProjectPackage("github.com/ConradIrwin/foo/bar") {
		t.Error("wrong packges being marked in project")
	}

}

type LoggoWrapper struct {
	loggo.Logger
}

func (lw *LoggoWrapper) Printf(format string, v ...interface{}) {
	lw.Logger.Warningf(format, v...)
}

func TestConfiguringCustomLogger(t *testing.T) {

	l1 := log.New(os.Stdout, "", log.Lshortfile)

	l2 := &LoggoWrapper{loggo.GetLogger("test")}

	var testCases = []struct {
		config Configuration
		notify bool
		msg    string
	}{
		{
			config: Configuration{ReleaseStage: "production", NotifyReleaseStages: []string{"development", "production"}, Logger: l1},
			notify: true,
			msg:    "Failed to assign log.Logger",
		},
		{
			config: Configuration{ReleaseStage: "production", NotifyReleaseStages: []string{"development", "production"}, Logger: l2},
			notify: true,
			msg:    "Failed to assign LoggoWrapper",
		},
	}

	for _, testCase := range testCases {
		Configure(testCase.config)

		// call printf just to illustrate it is present as the compiler does most of the hard work
		testCase.config.Logger.Printf("hello %s", "bugsnag")

	}
}