Skip to content

Commit 9fa4d02

Browse files
committed
Merge pull request #211 from arschles/pkt-test
fix(pkg/sshd/server_test.go): write test for gitPktLine (WIP)
2 parents d0e0952 + 91ef329 commit 9fa4d02

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

pkg/sshd/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ func Ping(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
334334
return nil, nil
335335
}
336336

337-
// gitPktLine writes a line following the git protocol
338-
// https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt
337+
// gitPktLine writes a line following the pkt-line git protocol. See https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt for the protocol and https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt for its usage.
339338
func gitPktLine(w io.Writer, s string) error {
340339
_, err := fmt.Fprintf(w, "%04x%s", len(s)+4, s)
341340
return err

pkg/sshd/server_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package sshd
22

33
import (
4+
"bytes"
5+
"fmt"
46
"net"
57
"testing"
68
"time"
79

810
"github.com/deis/builder/pkg/controller"
911

1012
"github.com/Masterminds/cookoo"
13+
"github.com/arschles/assert"
1114
"github.com/deis/builder/pkg/cleaner"
1215
"golang.org/x/crypto/ssh"
1316
)
@@ -19,6 +22,17 @@ const (
1922
gitHome = "/git"
2023
)
2124

25+
func TestGitPktLine(t *testing.T) {
26+
b := new(bytes.Buffer)
27+
str := "hello world"
28+
err := gitPktLine(b, str)
29+
assert.NoErr(t, err)
30+
outStr := string(b.Bytes())
31+
assert.True(t, len(outStr) > 4, "output string <= 4 chars")
32+
assert.Equal(t, outStr[:4], fmt.Sprintf("%04x", len(str)+4), "hex prefix")
33+
assert.Equal(t, outStr[4:], str, "remainder of string")
34+
}
35+
2236
// TestServer tests the SSH server.
2337
//
2438
// This listens on the non-standard port 2244 of localhost. This will generate

0 commit comments

Comments
 (0)