本文整理汇总了Golang中testing.T.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Error方法的具体用法?Golang T.Error怎么用?Golang T.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startSleepCommand
func startSleepCommand(t *testing.T) *exec.Cmd {
cmd := exec.Command("sh", "-c", "sleep 100")
if err := cmd.Start(); err != nil {
t.Error(err)
}
return cmd
}
示例2: TestPerimeter
func TestPerimeter(t *testing.T) {
//Testing for circle
for _, pair := range tests {
c := Circle{pair.x, pair.y, pair.r}
v := c.perimeter()
if v != pair.perimeterC {
t.Error(
"For", pair.x, pair.y, pair.r,
"expected", pair.perimeterC,
"got", v,
)
}
}
//Testing for rectangle
for _, pair1 := range testsRectanglePerimeter {
r := Rectangle{pair1.x1, pair1.y1, pair1.x2, pair1.y2}
v := r.perimeter()
if v != pair1.perimeterR {
t.Error(
"For", pair1.x1, pair1.y1, pair1.x2, pair1.y2,
"expected", pair1.perimeterR,
"got", v,
)
}
}
}
示例3: TestConnQueryScan
func TestConnQueryScan(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn)
var sum, rowCount int32
rows, err := conn.Query("select generate_series(1,$1)", 10)
if err != nil {
t.Fatalf("conn.Query failed: ", err)
}
defer rows.Close()
for rows.Next() {
var n int32
rows.Scan(&n)
sum += n
rowCount++
}
if rows.Err() != nil {
t.Fatalf("conn.Query failed: ", err)
}
if rowCount != 10 {
t.Error("Select called onDataRow wrong number of times")
}
if sum != 55 {
t.Error("Wrong values returned")
}
}
示例4: TestLinesToIgnore
func TestLinesToIgnore(t *testing.T) {
// it 'ignores empty lines' do
// expect(env("\n \t \nfoo=bar\n \nfizz=buzz")).to eql('foo' => 'bar', 'fizz' => 'buzz')
if !isIgnoredLine("\n") {
t.Error("Line with nothing but line break wasn't ignored")
}
if !isIgnoredLine("\t\t ") {
t.Error("Line full of whitespace wasn't ignored")
}
// it 'ignores comment lines' do
// expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql('foo' => 'bar')
if !isIgnoredLine("# comment") {
t.Error("Comment wasn't ignored")
}
if !isIgnoredLine("\t#comment") {
t.Error("Indented comment wasn't ignored")
}
// make sure we're not getting false positives
if isIgnoredLine("export OPTION_B='\\n'") {
t.Error("ignoring a perfectly valid line to parse")
}
}
示例5: TestWatchFork
func TestWatchFork(t *testing.T) {
if skipTest(t) {
return
}
pid := os.Getpid()
tw := newTestWatcher(t)
// no watches added yet, so this fork event will no be captured
runCommand(t, "date")
// watch fork events for this process
if err := tw.watcher.Watch(pid, PROC_EVENT_FORK); err != nil {
t.Error(err)
}
// this fork event will be captured,
// the exec and exit events will not be captured
runCommand(t, "cal")
tw.close()
if expectEvents(t, 1, "forks", tw.events.forks) {
expectEventPid(t, "fork", pid, tw.events.forks[0])
}
expectEvents(t, 0, "execs", tw.events.execs)
expectEvents(t, 0, "exits", tw.events.exits)
}
示例6: TestDo_rateLimit_errorResponse
// ensure rate limit is still parsed, even for error responses
func TestDo_rateLimit_errorResponse(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add(headerRateLimit, "60")
w.Header().Add(headerRateRemaining, "59")
w.Header().Add(headerRateReset, "1372700873")
http.Error(w, "Bad Request", 400)
})
req, _ := client.NewRequest("GET", "/", nil)
_, err := client.Do(req, nil)
if err == nil {
t.Error("Expected error to be returned.")
}
if _, ok := err.(*RateLimitError); ok {
t.Errorf("Did not expect a *RateLimitError error; got %#v.", err)
}
if got, want := client.Rate().Limit, 60; got != want {
t.Errorf("Client rate limit = %v, want %v", got, want)
}
if got, want := client.Rate().Remaining, 59; got != want {
t.Errorf("Client rate remaining = %v, want %v", got, want)
}
reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC)
if client.Rate().Reset.UTC() != reset {
t.Errorf("Client rate reset = %v, want %v", client.Rate().Reset, reset)
}
}
示例7: TestIntegrationLog
func TestIntegrationLog(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration tests in short mode.")
}
oService := &routing.Service{Client: client}
opts, err := oService.GetOptimizations(&routing.RouteQuery{
Limit: 1,
})
if err != nil {
t.Error("Error occured in external service:", err)
return
}
if len(opts) < 1 {
t.Skip("Not enough routes to test activity stream")
}
opt, err := oService.GetOptimization(&routing.OptimizationParameters{
ProblemID: opts[0].ProblemID,
})
if len(opt.Routes) < 1 {
t.Skip("Not enough routes to test activity stream")
}
err = service.Log("TestMessage", opt.Routes[0].ID)
if err != nil {
t.Error(err)
}
}
示例8: testGetConsumersInGroup
func testGetConsumersInGroup(t *testing.T) {
consumers, err := coordinator.GetConsumersInGroup(consumerGroup)
if err != nil {
t.Error(err)
}
assert(t, len(consumers), 1)
}
示例9: testRegisterConsumer
func testRegisterConsumer(t *testing.T) {
subscription := make(map[string]int)
subscription["topic1"] = 1
consumerInfo := &ConsumerInfo{
Version: int16(1),
Subscription: subscription,
Pattern: whiteListPattern,
Timestamp: time.Now().Unix(),
}
topicCount := &WildcardTopicsToNumStreams{
Coordinator: coordinator,
ConsumerId: fmt.Sprintf(consumerIdPattern, 0),
TopicFilter: NewWhiteList("topic1"),
NumStreams: 1,
ExcludeInternalTopics: true,
}
err := coordinator.RegisterConsumer(fmt.Sprintf(consumerIdPattern, 0), consumerGroup, topicCount)
if err != nil {
t.Error(err)
}
actualConsumerInfo, err := coordinator.GetConsumerInfo(fmt.Sprintf(consumerIdPattern, 0), consumerGroup)
assert(t, actualConsumerInfo.Version, consumerInfo.Version)
assert(t, actualConsumerInfo.Subscription, consumerInfo.Subscription)
assert(t, actualConsumerInfo.Pattern, consumerInfo.Pattern)
}
示例10: TestUnionFsRemoveAll
func TestUnionFsRemoveAll(t *testing.T) {
wd, clean := setupUfs(t)
defer clean()
err := os.MkdirAll(wd+"/ro/dir/subdir", 0755)
CheckSuccess(err)
contents := "hello"
fn := wd + "/ro/dir/subdir/y"
err = ioutil.WriteFile(fn, []byte(contents), 0644)
CheckSuccess(err)
freezeRo(wd + "/ro")
err = os.RemoveAll(wd + "/mnt/dir")
if err != nil {
t.Error("Should delete all")
}
for _, f := range []string{"dir/subdir/y", "dir/subdir", "dir"} {
if fi, _ := os.Lstat(filepath.Join(wd, "mount", f)); fi != nil {
t.Errorf("file %s should have disappeared: %v", f, fi)
}
}
names, err := Readdirnames(wd + "/rw/DELETIONS")
CheckSuccess(err)
if len(names) != 3 {
t.Fatal("unexpected names", names)
}
}
示例11: TestMarshalBinary
func TestMarshalBinary(t *testing.T) {
s1 := New(testdata.TwoHoursData[0].T)
for _, p := range testdata.TwoHoursData {
s1.Push(p.T, p.V)
}
it1 := s1.Iter()
it1.Next()
b, err := s1.MarshalBinary()
if err != nil {
t.Error(err)
}
s2 := New(s1.T0)
err = s2.UnmarshalBinary(b)
if err != nil {
t.Error(err)
}
it := s2.Iter()
for _, w := range testdata.TwoHoursData {
if !it.Next() {
t.Fatalf("Next()=false, want true")
}
tt, vv := it.Values()
// t.Logf("it.Values()=(%+v, %+v)\n", time.Unix(int64(tt), 0), vv)
if w.T != tt || w.V != vv {
t.Errorf("Values()=(%v,%v), want (%v,%v)\n", tt, vv, w.T, w.V)
}
}
}
示例12: TestTournamentAndElitism
func TestTournamentAndElitism(t *testing.T) {
var (
src = rand.NewSource(time.Now().UnixNano())
rng = rand.New(src)
nbGenes = 2
size = 3
indis = makeIndividuals(size, nbGenes, rng)
)
for i := 0; i < size; i++ {
indis[i] = makeIndividual(nbGenes, rng)
indis[i].Fitness = float64(i)
}
var original = make([]Individual, len(indis))
copy(original, indis)
// All the individuals participate in the tournament
var (
elitism = SelElitism{}
tournament = SelTournament{size}
elite, _ = elitism.Apply(size, indis, rng)
tourney, _ = tournament.Apply(size, indis, rng)
)
elite.Sort()
tourney.Sort()
// Check the individual is from the initial population
if elite[0].Fitness != tourney[0].Fitness {
t.Error("Elitism and full tournament selection differed")
}
}
示例13: TestMultiWriter
func TestMultiWriter(t *testing.T) {
sha1 := sha1.New()
sink := new(bytes.Buffer)
mw := MultiWriter(sha1, sink)
sourceString := "My input text."
source := strings.NewReader(sourceString)
written, err := Copy(mw, source)
if written != int64(len(sourceString)) {
t.Errorf("short write of %d, not %d", written, len(sourceString))
}
if err != nil {
t.Errorf("unexpected error: %v", err)
}
sha1hex := fmt.Sprintf("%x", sha1.Sum())
if sha1hex != "01cb303fa8c30a64123067c5aa6284ba7ec2d31b" {
t.Error("incorrect sha1 value")
}
if sink.String() != sourceString {
t.Errorf("expected %q; got %q", sourceString, sink.String())
}
}
示例14: Test_janitar
func Test_janitar(t *testing.T) {
time.Sleep(12 * time.Second)
if cache1.Len().Get() == 99999 {
t.Error("err")
return
}
}
示例15: TestCacheComplete
func TestCacheComplete(t *testing.T) {
paths := DefaultPaths()
if len(paths) == 0 {
t.Skip("No default paths available")
}
tests := []string{"mscorlib.dll", "System.dll"}
t.Log(paths)
c := Cache{paths: paths}
for _, test := range tests {
if asm, err := c.Load(test); err != nil {
t.Error(err)
} else {
t.Logf("Found %s (%s)", test, asm.Name())
}
}
tests2 := []content.Type{
content.Type{Name: content.FullyQualifiedName{Absolute: "net://type/System.String"}},
}
for _, test := range tests2 {
if res, err := c.Complete(&test); err != nil {
t.Error(err)
} else {
t.Log(res)
}
}
}