Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(601)

Delta Between Two Patch Sets: ssh/messages_test.go

Issue 14767043: code review 14767043: go.crypto/ssh: additional coverage of message unmarshaling (Closed)
Left Patch Set: diff -r 5ff5636e18c9 https://code.google.com/p/go.crypto Created 10 years, 5 months ago
Right Patch Set: diff -r 32844aa1ae54 https://code.google.com/p/go.crypto Created 10 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package ssh 5 package ssh
6 6
7 import ( 7 import (
8 "math/big" 8 "math/big"
9 "math/rand" 9 "math/rand"
10 "reflect" 10 "reflect"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 func TestUnmarshalEmptyPacket(t *testing.T) { 81 func TestUnmarshalEmptyPacket(t *testing.T) {
82 var b []byte 82 var b []byte
83 var m channelRequestSuccessMsg 83 var m channelRequestSuccessMsg
84 err := unmarshal(&m, b, msgChannelRequest) 84 err := unmarshal(&m, b, msgChannelRequest)
85 want := ParseError{msgChannelRequest} 85 want := ParseError{msgChannelRequest}
86 if _, ok := err.(ParseError); !ok { 86 if _, ok := err.(ParseError); !ok {
87 » » t.Fatalf("expected %T, got %T", want, err) 87 » » t.Fatalf("got %T, want %T", err, want)
hanwen-google 2013/10/17 05:53:37 i've been taught to use the "got X want Y" format
dfc 2013/10/19 10:59:56 Done.
88 } 88 }
89 if got := err.(ParseError); want != got { 89 if got := err.(ParseError); want != got {
90 » » t.Fatal("expected %#v, got %#v", want, got) 90 » » t.Fatal("got %#v, want %#v", got, want)
91 } 91 }
92 } 92 }
93 93
94 func TestUnmarshalUnexpectedPacket(t *testing.T) { 94 func TestUnmarshalUnexpectedPacket(t *testing.T) {
95 type S struct { 95 type S struct {
96 I uint32 96 I uint32
97 S string 97 S string
98 B bool 98 B bool
99 } 99 }
100 100
101 s := S{42, "hello", true} 101 s := S{42, "hello", true}
102 packet := marshal(42, s) 102 packet := marshal(42, s)
103 roundtrip := S{} 103 roundtrip := S{}
104 err := unmarshal(&roundtrip, packet, 43) 104 err := unmarshal(&roundtrip, packet, 43)
105 if err == nil { 105 if err == nil {
106 t.Fatal("expected error, not nil") 106 t.Fatal("expected error, not nil")
107 } 107 }
108 » want := "ssh: unexpected message type 42 (expected 43)" 108 » want := UnexpectedMessageError{43, 42}
109 » if got := err.Error(); want != got { 109 » if got, ok := err.(UnexpectedMessageError); !ok || want != got {
hanwen-google 2013/10/17 05:53:37 can you do a type conversion instead? It's less se
dfc 2013/10/19 10:59:56 Done.
dfc 2013/10/19 10:59:56 PTAL.
110 t.Fatal("expected %q, got %q", want, got) 110 t.Fatal("expected %q, got %q", want, got)
111 } 111 }
112 } 112 }
113 113
114 func TestBareMarshalUnmarshal(t *testing.T) { 114 func TestBareMarshalUnmarshal(t *testing.T) {
115 type S struct { 115 type S struct {
116 I uint32 116 I uint32
117 S string 117 S string
118 B bool 118 B bool
119 } 119 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 marshal(msgKexDHInit, _kexDHInitMsg) 223 marshal(msgKexDHInit, _kexDHInitMsg)
224 } 224 }
225 } 225 }
226 226
227 func BenchmarkUnmarshalKexDHInitMsg(b *testing.B) { 227 func BenchmarkUnmarshalKexDHInitMsg(b *testing.B) {
228 m := new(kexDHInitMsg) 228 m := new(kexDHInitMsg)
229 for i := 0; i < b.N; i++ { 229 for i := 0; i < b.N; i++ {
230 unmarshal(m, _kexDHInit, msgKexDHInit) 230 unmarshal(m, _kexDHInit, msgKexDHInit)
231 } 231 }
232 } 232 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b