aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/format')
-rw-r--r--plumbing/format/commitgraph/commitgraph_test.go24
-rw-r--r--plumbing/format/gitattributes/dir.go5
-rw-r--r--plumbing/format/gitattributes/dir_test.go28
-rw-r--r--plumbing/format/gitignore/dir.go5
-rw-r--r--plumbing/format/gitignore/dir_test.go27
-rw-r--r--plumbing/format/packfile/packfile_test.go42
-rw-r--r--plumbing/format/packfile/parser_test.go28
-rw-r--r--plumbing/format/pktline/encoder_test.go37
-rw-r--r--plumbing/format/pktline/scanner_test.go31
9 files changed, 72 insertions, 155 deletions
diff --git a/plumbing/format/commitgraph/commitgraph_test.go b/plumbing/format/commitgraph/commitgraph_test.go
index de61ae9..4540ae3 100644
--- a/plumbing/format/commitgraph/commitgraph_test.go
+++ b/plumbing/format/commitgraph/commitgraph_test.go
@@ -1,11 +1,11 @@
package commitgraph_test
import (
- "io/ioutil"
"os"
- "path"
"testing"
+ "github.com/go-git/go-billy/v5"
+ "github.com/go-git/go-billy/v5/util"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/commitgraph"
@@ -21,8 +21,8 @@ type CommitgraphSuite struct {
var _ = Suite(&CommitgraphSuite{})
-func testDecodeHelper(c *C, path string) {
- reader, err := os.Open(path)
+func testDecodeHelper(c *C, fs billy.Filesystem, path string) {
+ reader, err := fs.Open(path)
c.Assert(err, IsNil)
defer reader.Close()
index, err := commitgraph.OpenFileIndex(reader)
@@ -76,7 +76,7 @@ func testDecodeHelper(c *C, path string) {
func (s *CommitgraphSuite) TestDecode(c *C) {
fixtures.ByTag("commit-graph").Test(c, func(f *fixtures.Fixture) {
dotgit := f.DotGit()
- testDecodeHelper(c, path.Join(dotgit.Root(), "objects", "info", "commit-graph"))
+ testDecodeHelper(c, dotgit, dotgit.Join("objects", "info", "commit-graph"))
})
}
@@ -84,22 +84,23 @@ func (s *CommitgraphSuite) TestReencode(c *C) {
fixtures.ByTag("commit-graph").Test(c, func(f *fixtures.Fixture) {
dotgit := f.DotGit()
- reader, err := os.Open(path.Join(dotgit.Root(), "objects", "info", "commit-graph"))
+ reader, err := dotgit.Open(dotgit.Join("objects", "info", "commit-graph"))
c.Assert(err, IsNil)
defer reader.Close()
index, err := commitgraph.OpenFileIndex(reader)
c.Assert(err, IsNil)
- writer, err := ioutil.TempFile(dotgit.Root(), "commit-graph")
+ writer, err := util.TempFile(dotgit, "", "commit-graph")
c.Assert(err, IsNil)
tmpName := writer.Name()
defer os.Remove(tmpName)
+
encoder := commitgraph.NewEncoder(writer)
err = encoder.Encode(index)
c.Assert(err, IsNil)
writer.Close()
- testDecodeHelper(c, tmpName)
+ testDecodeHelper(c, dotgit, tmpName)
})
}
@@ -107,7 +108,7 @@ func (s *CommitgraphSuite) TestReencodeInMemory(c *C) {
fixtures.ByTag("commit-graph").Test(c, func(f *fixtures.Fixture) {
dotgit := f.DotGit()
- reader, err := os.Open(path.Join(dotgit.Root(), "objects", "info", "commit-graph"))
+ reader, err := dotgit.Open(dotgit.Join("objects", "info", "commit-graph"))
c.Assert(err, IsNil)
index, err := commitgraph.OpenFileIndex(reader)
c.Assert(err, IsNil)
@@ -119,15 +120,16 @@ func (s *CommitgraphSuite) TestReencodeInMemory(c *C) {
}
reader.Close()
- writer, err := ioutil.TempFile(dotgit.Root(), "commit-graph")
+ writer, err := util.TempFile(dotgit, "", "commit-graph")
c.Assert(err, IsNil)
tmpName := writer.Name()
defer os.Remove(tmpName)
+
encoder := commitgraph.NewEncoder(writer)
err = encoder.Encode(memoryIndex)
c.Assert(err, IsNil)
writer.Close()
- testDecodeHelper(c, tmpName)
+ testDecodeHelper(c, dotgit, tmpName)
})
}
diff --git a/plumbing/format/gitattributes/dir.go b/plumbing/format/gitattributes/dir.go
index b0dc82b..123fe25 100644
--- a/plumbing/format/gitattributes/dir.go
+++ b/plumbing/format/gitattributes/dir.go
@@ -2,7 +2,6 @@ package gitattributes
import (
"os"
- "os/user"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5/plumbing/format/config"
@@ -106,12 +105,12 @@ func loadPatterns(fs billy.Filesystem, path string) ([]MatchAttribute, error) {
// the function will return nil. The function assumes fs is rooted at the root
// filesystem.
func LoadGlobalPatterns(fs billy.Filesystem) (attributes []MatchAttribute, err error) {
- usr, err := user.Current()
+ home, err := os.UserHomeDir()
if err != nil {
return
}
- return loadPatterns(fs, fs.Join(usr.HomeDir, gitconfigFile))
+ return loadPatterns(fs, fs.Join(home, gitconfigFile))
}
// LoadSystemPatterns loads gitattributes patterns and attributes from the
diff --git a/plumbing/format/gitattributes/dir_test.go b/plumbing/format/gitattributes/dir_test.go
index 0ecc3b3..1b9a20d 100644
--- a/plumbing/format/gitattributes/dir_test.go
+++ b/plumbing/format/gitattributes/dir_test.go
@@ -2,7 +2,6 @@ package gitattributes
import (
"os"
- "os/user"
"strconv"
"github.com/go-git/go-billy/v5"
@@ -23,8 +22,7 @@ type MatcherSuite struct {
var _ = Suite(&MatcherSuite{})
func (s *MatcherSuite) SetUpTest(c *C) {
- // setup root that contains user home
- usr, err := user.Current()
+ home, err := os.UserHomeDir()
c.Assert(err, IsNil)
gitAttributesGlobal := func(fs billy.Filesystem, filename string) {
@@ -62,59 +60,59 @@ func (s *MatcherSuite) SetUpTest(c *C) {
fs.MkdirAll("vendor/github.com", os.ModePerm)
fs.MkdirAll("vendor/gopkg.in", os.ModePerm)
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.GFS = fs
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
- _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitattributes_global")) + "\n"))
+ _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(home, ".gitattributes_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.RFS = fs
// root that contains user home, but missing ~/.gitconfig
fs = memfs.New()
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.MCFS = fs
// setup root that contains user home, but missing attributesfile entry
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.MEFS = fs
// setup root that contains user home, but missing .gitattributes
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
- _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitattributes_global")) + "\n"))
+ _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(home, ".gitattributes_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go
index 922c458..7cea50c 100644
--- a/plumbing/format/gitignore/dir.go
+++ b/plumbing/format/gitignore/dir.go
@@ -5,7 +5,6 @@ import (
"bytes"
"io/ioutil"
"os"
- "os/user"
"strings"
"github.com/go-git/go-billy/v5"
@@ -116,12 +115,12 @@ func loadPatterns(fs billy.Filesystem, path string) (ps []Pattern, err error) {
//
// The function assumes fs is rooted at the root filesystem.
func LoadGlobalPatterns(fs billy.Filesystem) (ps []Pattern, err error) {
- usr, err := user.Current()
+ home, err := os.UserHomeDir()
if err != nil {
return
}
- return loadPatterns(fs, fs.Join(usr.HomeDir, gitconfigFile))
+ return loadPatterns(fs, fs.Join(home, gitconfigFile))
}
// LoadSystemPatterns loads gitignore patterns from from the gitignore file
diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go
index a3e7ba6..94ed7be 100644
--- a/plumbing/format/gitignore/dir_test.go
+++ b/plumbing/format/gitignore/dir_test.go
@@ -2,7 +2,6 @@ package gitignore
import (
"os"
- "os/user"
"strconv"
"github.com/go-git/go-billy/v5"
@@ -55,23 +54,23 @@ func (s *MatcherSuite) SetUpTest(c *C) {
s.GFS = fs
// setup root that contains user home
- usr, err := user.Current()
+ home, err := os.UserHomeDir()
c.Assert(err, IsNil)
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
- _, err = f.Write([]byte(" excludesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitignore_global")) + "\n"))
+ _, err = f.Write([]byte(" excludesfile = " + strconv.Quote(fs.Join(home, ".gitignore_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, ".gitignore_global"))
+ f, err = fs.Create(fs.Join(home, ".gitignore_global"))
c.Assert(err, IsNil)
_, err = f.Write([]byte("# IntelliJ\n"))
c.Assert(err, IsNil)
@@ -86,10 +85,10 @@ func (s *MatcherSuite) SetUpTest(c *C) {
// root that contains user home, but missing ~/.gitconfig
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, ".gitignore_global"))
+ f, err = fs.Create(fs.Join(home, ".gitignore_global"))
c.Assert(err, IsNil)
_, err = f.Write([]byte("# IntelliJ\n"))
c.Assert(err, IsNil)
@@ -104,17 +103,17 @@ func (s *MatcherSuite) SetUpTest(c *C) {
// setup root that contains user home, but missing excludesfile entry
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, ".gitignore_global"))
+ f, err = fs.Create(fs.Join(home, ".gitignore_global"))
c.Assert(err, IsNil)
_, err = f.Write([]byte("# IntelliJ\n"))
c.Assert(err, IsNil)
@@ -129,14 +128,14 @@ func (s *MatcherSuite) SetUpTest(c *C) {
// setup root that contains user home, but missing .gitnignore
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
- _, err = f.Write([]byte(" excludesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitignore_global")) + "\n"))
+ _, err = f.Write([]byte(" excludesfile = " + strconv.Quote(fs.Join(home, ".gitignore_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
diff --git a/plumbing/format/packfile/packfile_test.go b/plumbing/format/packfile/packfile_test.go
index 8b1b934..60c7c73 100644
--- a/plumbing/format/packfile/packfile_test.go
+++ b/plumbing/format/packfile/packfile_test.go
@@ -4,7 +4,6 @@ import (
"io"
"math"
- "github.com/go-git/go-billy/v5/osfs"
fixtures "github.com/go-git/go-git-fixtures/v4"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/idxfile"
@@ -109,14 +108,10 @@ var expectedEntries = map[plumbing.Hash]int64{
func (s *PackfileSuite) SetUpTest(c *C) {
s.f = fixtures.Basic().One()
- fs := osfs.New("")
- f, err := fs.Open(s.f.Packfile().Name())
- c.Assert(err, IsNil)
-
s.idx = idxfile.NewMemoryIndex()
c.Assert(idxfile.NewDecoder(s.f.Idx()).Decode(s.idx), IsNil)
- s.p = packfile.NewPackfile(s.idx, fs, f)
+ s.p = packfile.NewPackfile(s.idx, fixtures.Filesystem, s.f.Packfile())
}
func (s *PackfileSuite) TearDownTest(c *C) {
@@ -126,11 +121,8 @@ func (s *PackfileSuite) TearDownTest(c *C) {
func (s *PackfileSuite) TestDecode(c *C) {
fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
index := getIndexFromIdxFile(f.Idx())
- fs := osfs.New("")
- pf, err := fs.Open(f.Packfile().Name())
- c.Assert(err, IsNil)
- p := packfile.NewPackfile(index, fs, pf)
+ p := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile())
defer p.Close()
for _, h := range expectedHashes {
@@ -145,11 +137,8 @@ func (s *PackfileSuite) TestDecodeByTypeRefDelta(c *C) {
f := fixtures.Basic().ByTag("ref-delta").One()
index := getIndexFromIdxFile(f.Idx())
- fs := osfs.New("")
- pf, err := fs.Open(f.Packfile().Name())
- c.Assert(err, IsNil)
- packfile := packfile.NewPackfile(index, fs, pf)
+ packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile())
defer packfile.Close()
iter, err := packfile.GetByType(plumbing.CommitObject)
@@ -161,6 +150,7 @@ func (s *PackfileSuite) TestDecodeByTypeRefDelta(c *C) {
if err == io.EOF {
break
}
+
count++
c.Assert(err, IsNil)
c.Assert(obj.Type(), Equals, plumbing.CommitObject)
@@ -180,11 +170,8 @@ func (s *PackfileSuite) TestDecodeByType(c *C) {
fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
for _, t := range ts {
index := getIndexFromIdxFile(f.Idx())
- fs := osfs.New("")
- pf, err := fs.Open(f.Packfile().Name())
- c.Assert(err, IsNil)
- packfile := packfile.NewPackfile(index, fs, pf)
+ packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile())
defer packfile.Close()
iter, err := packfile.GetByType(t)
@@ -201,14 +188,11 @@ func (s *PackfileSuite) TestDecodeByType(c *C) {
func (s *PackfileSuite) TestDecodeByTypeConstructor(c *C) {
f := fixtures.Basic().ByTag("packfile").One()
index := getIndexFromIdxFile(f.Idx())
- fs := osfs.New("")
- pf, err := fs.Open(f.Packfile().Name())
- c.Assert(err, IsNil)
- packfile := packfile.NewPackfile(index, fs, pf)
+ packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile())
defer packfile.Close()
- _, err = packfile.GetByType(plumbing.OFSDeltaObject)
+ _, err := packfile.GetByType(plumbing.OFSDeltaObject)
c.Assert(err, Equals, plumbing.ErrInvalidType)
_, err = packfile.GetByType(plumbing.REFDeltaObject)
@@ -269,24 +253,20 @@ func assertObjects(c *C, s storer.EncodedObjectStorer, expects []string) {
}
func getIndexFromIdxFile(r io.Reader) idxfile.Index {
- idxf := idxfile.NewMemoryIndex()
- d := idxfile.NewDecoder(r)
- if err := d.Decode(idxf); err != nil {
+ idx := idxfile.NewMemoryIndex()
+ if err := idxfile.NewDecoder(r).Decode(idx); err != nil {
panic(err)
}
- return idxf
+ return idx
}
func (s *PackfileSuite) TestSize(c *C) {
f := fixtures.Basic().ByTag("ref-delta").One()
index := getIndexFromIdxFile(f.Idx())
- fs := osfs.New("")
- pf, err := fs.Open(f.Packfile().Name())
- c.Assert(err, IsNil)
- packfile := packfile.NewPackfile(index, fs, pf)
+ packfile := packfile.NewPackfile(index, fixtures.Filesystem, f.Packfile())
defer packfile.Close()
// Get the size of binary.jpg, which is not delta-encoded.
diff --git a/plumbing/format/packfile/parser_test.go b/plumbing/format/packfile/parser_test.go
index 57a9c17..b0b4af8 100644
--- a/plumbing/format/packfile/parser_test.go
+++ b/plumbing/format/packfile/parser_test.go
@@ -2,14 +2,16 @@ package packfile_test
import (
"io"
+ "os"
"testing"
- git "github.com/go-git/go-git/v5"
+ "github.com/go-git/go-billy/v5/osfs"
+ "github.com/go-git/go-billy/v5/util"
+ fixtures "github.com/go-git/go-git-fixtures/v4"
+ "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/packfile"
"github.com/go-git/go-git/v5/plumbing/storer"
-
- fixtures "github.com/go-git/go-git-fixtures/v4"
. "gopkg.in/check.v1"
)
@@ -78,40 +80,46 @@ func (s *ParserSuite) TestParserHashes(c *C) {
}
func (s *ParserSuite) TestThinPack(c *C) {
+ fs := osfs.New(os.TempDir())
+ path, err := util.TempDir(fs, "", "")
+ c.Assert(err, IsNil)
// Initialize an empty repository
- fs, err := git.PlainInit(c.MkDir(), true)
+ r, err := git.PlainInit(path, true)
c.Assert(err, IsNil)
// Try to parse a thin pack without having the required objects in the repo to
// see if the correct errors are returned
thinpack := fixtures.ByTag("thinpack").One()
scanner := packfile.NewScanner(thinpack.Packfile())
- parser, err := packfile.NewParserWithStorage(scanner, fs.Storer) // ParserWithStorage writes to the storer all parsed objects!
+ parser, err := packfile.NewParserWithStorage(scanner, r.Storer) // ParserWithStorage writes to the storer all parsed objects!
c.Assert(err, IsNil)
_, err = parser.Parse()
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
+ path, err = util.TempDir(fs, "", "")
+ c.Assert(err, IsNil)
+
// start over with a clean repo
- fs, err = git.PlainInit(c.MkDir(), true)
+ r, err = git.PlainInit(path, true)
c.Assert(err, IsNil)
// Now unpack a base packfile into our empty repo:
f := fixtures.ByURL("https://github.com/spinnaker/spinnaker.git").One()
- w, err := fs.Storer.(storer.PackfileWriter).PackfileWriter()
+ w, err := r.Storer.(storer.PackfileWriter).PackfileWriter()
c.Assert(err, IsNil)
_, err = io.Copy(w, f.Packfile())
c.Assert(err, IsNil)
w.Close()
// Check that the test object that will come with our thin pack is *not* in the repo
- _, err = fs.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head))
+ _, err = r.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head))
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
// Now unpack the thin pack:
scanner = packfile.NewScanner(thinpack.Packfile())
- parser, err = packfile.NewParserWithStorage(scanner, fs.Storer) // ParserWithStorage writes to the storer all parsed objects!
+ parser, err = packfile.NewParserWithStorage(scanner, r.Storer) // ParserWithStorage writes to the storer all parsed objects!
c.Assert(err, IsNil)
h, err := parser.Parse()
@@ -119,7 +127,7 @@ func (s *ParserSuite) TestThinPack(c *C) {
c.Assert(h, Equals, plumbing.NewHash("1288734cbe0b95892e663221d94b95de1f5d7be8"))
// Check that our test object is now accessible
- _, err = fs.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head))
+ _, err = r.Storer.EncodedObject(plumbing.CommitObject, plumbing.NewHash(thinpack.Head))
c.Assert(err, IsNil)
}
diff --git a/plumbing/format/pktline/encoder_test.go b/plumbing/format/pktline/encoder_test.go
index 4a7c7b8..a6addd6 100644
--- a/plumbing/format/pktline/encoder_test.go
+++ b/plumbing/format/pktline/encoder_test.go
@@ -2,7 +2,6 @@ package pktline_test
import (
"bytes"
- "os"
"strings"
"testing"
@@ -211,39 +210,3 @@ func (s *SuiteEncoder) TestEncodef(c *C) {
expected := []byte("000c foo 42\n")
c.Assert(buf.Bytes(), DeepEquals, expected)
}
-
-func ExampleEncoder() {
- // Create an encoder that writes pktlines to stdout.
- e := pktline.NewEncoder(os.Stdout)
-
- // Encode some data as a new pkt-line.
- _ = e.Encode([]byte("data\n")) // error checks removed for brevity
-
- // Encode a flush-pkt.
- _ = e.Flush()
-
- // Encode a couple of byte slices and a flush in one go. Each of
- // them will end up as payloads of their own pktlines.
- _ = e.Encode(
- []byte("hello\n"),
- []byte("world!\n"),
- pktline.Flush,
- )
-
- // You can also encode strings:
- _ = e.EncodeString(
- "foo\n",
- "bar\n",
- pktline.FlushString,
- )
-
- // You can also format and encode a payload:
- _ = e.Encodef(" %s %d\n", "foo", 42)
- // Output:
- // 0009data
- // 0000000ahello
- // 000bworld!
- // 00000008foo
- // 0008bar
- // 0000000c foo 42
-}
diff --git a/plumbing/format/pktline/scanner_test.go b/plumbing/format/pktline/scanner_test.go
index 479ad77..60b6224 100644
--- a/plumbing/format/pktline/scanner_test.go
+++ b/plumbing/format/pktline/scanner_test.go
@@ -217,34 +217,3 @@ func sectionsExample(c *C, nSections, nLines int) io.Reader {
return &buf
}
-
-func ExampleScanner() {
- // A reader is needed as input.
- input := strings.NewReader("000ahello\n" +
- "000bworld!\n" +
- "0000",
- )
-
- // Create the scanner...
- s := pktline.NewScanner(input)
-
- // and scan every pkt-line found in the input.
- for s.Scan() {
- payload := s.Bytes()
- if len(payload) == 0 { // zero sized payloads correspond to flush-pkts.
- fmt.Println("FLUSH-PKT DETECTED")
- } else { // otherwise, you will be able to access the full payload.
- fmt.Printf("PAYLOAD = %q\n", string(payload))
- }
- }
-
- // this will catch any error when reading from the input, if any.
- if s.Err() != nil {
- fmt.Println(s.Err())
- }
-
- // Output:
- // PAYLOAD = "hello\n"
- // PAYLOAD = "world!\n"
- // FLUSH-PKT DETECTED
-}