github.com/echohead/hub@v2.2.1+incompatible/github/crash_report_test.go (about)

     1  package github
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/github/hub/Godeps/_workspace/src/github.com/bmizerany/assert"
     7  	"github.com/github/hub/fixtures"
     8  )
     9  
    10  func TestStackRemoveSelfAndPanic(t *testing.T) {
    11  	actual := `goroutine 1 [running]:
    12  runtime.panic(0x2bca00, 0x665b8a)
    13  	/usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
    14  github.com/jingweno/gh/github.ReportCrash(0xc2000b5000, 0xc2000b49c0)
    15  	/Users/calavera/github/go/src/github.com/jingweno/gh/github/crash_report.go:16 +0x97
    16  github.com/jingweno/gh/commands.create(0x47f8a0, 0xc2000cf770)
    17  	/Users/calavera/github/go/src/github.com/jingweno/gh/commands/create.go:54 +0x63
    18  github.com/jingweno/gh/commands.(*Runner).Execute(0xc200094640, 0xc200094640, 0x21, 0xc2000b0a40)
    19  	/Users/calavera/github/go/src/github.com/jingweno/gh/commands/runner.go:72 +0x3b7
    20  main.main()
    21  	/Users/calavera/github/go/src/github.com/jingweno/gh/main.go:10 +0xad`
    22  
    23  	expected := `goroutine 1 [running]:
    24  github.com/jingweno/gh/commands.create(0x47f8a0, 0xc2000cf770)
    25  	/Users/calavera/github/go/src/github.com/jingweno/gh/commands/create.go:54 +0x63
    26  github.com/jingweno/gh/commands.(*Runner).Execute(0xc200094640, 0xc200094640, 0x21, 0xc2000b0a40)
    27  	/Users/calavera/github/go/src/github.com/jingweno/gh/commands/runner.go:72 +0x3b7
    28  main.main()
    29  	/Users/calavera/github/go/src/github.com/jingweno/gh/main.go:10 +0xad`
    30  
    31  	s := formatStack([]byte(actual))
    32  	assert.Equal(t, expected, s)
    33  }
    34  
    35  func TestSaveAlwaysReportOption(t *testing.T) {
    36  	checkSavedReportCrashOption(t, true, "a", "always")
    37  	checkSavedReportCrashOption(t, true, "always", "always")
    38  }
    39  
    40  func TestSaveNeverReportOption(t *testing.T) {
    41  	checkSavedReportCrashOption(t, false, "e", "never")
    42  	checkSavedReportCrashOption(t, false, "never", "never")
    43  }
    44  
    45  func TestDoesntSaveYesReportOption(t *testing.T) {
    46  	checkSavedReportCrashOption(t, false, "y", "")
    47  	checkSavedReportCrashOption(t, false, "yes", "")
    48  }
    49  
    50  func TestDoesntSaveNoReportOption(t *testing.T) {
    51  	checkSavedReportCrashOption(t, false, "n", "")
    52  	checkSavedReportCrashOption(t, false, "no", "")
    53  }
    54  
    55  func checkSavedReportCrashOption(t *testing.T, always bool, confirm, expected string) {
    56  	repo := fixtures.SetupTestRepo()
    57  	defer repo.TearDown()
    58  
    59  	saveReportConfiguration(confirm, always)
    60  	assert.Equal(t, expected, reportCrashConfig())
    61  }