git-module

fork of https://git.lin.moe/gogs/git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import (
 4	"bytes"
 5	"context"
 6	"testing"
 7
 8	"github.com/stretchr/testify/assert"
 9)
10
11func TestBlob(t *testing.T) {
12	ctx := context.Background()
13	expOutput := `This is a sample project students can use during Matthew's Git class.
14
15Here is an addition by me
16
17We can have a bit of fun with this repo, knowing that we can always reset it to a known good state.  We can apply labels, and branch, then add new code and merge it in to the master branch.
18
19As a quick reminder, this came from one of three locations in either SSH, Git, or HTTPS format:
20
21* git@github.com:matthewmccullough/hellogitworld.git
22* git://github.com/matthewmccullough/hellogitworld.git
23* https://matthewmccullough@github.com/matthewmccullough/hellogitworld.git
24
25We can, as an example effort, even modify this README and change it as if it were source code for the purposes of the class.
26
27This demo also includes an image with changes on a branch for examination of image diff on GitHub.
28`
29
30	blob := &Blob{
31		TreeEntry: &TreeEntry{
32			mode: EntryBlob,
33			typ:  ObjectBlob,
34			id:   testrepoMarks[39], // Blob ID of "README.txt" file
35			parent: &Tree{
36				repo: testrepo,
37			},
38		},
39	}
40
41	t.Run("get data all at once", func(t *testing.T) {
42		p, err := blob.Bytes(ctx)
43		assert.Nil(t, err)
44		assert.Equal(t, expOutput, string(p))
45	})
46
47	t.Run("get data with pipe", func(t *testing.T) {
48		stdout := new(bytes.Buffer)
49		err := blob.Pipe(ctx, stdout)
50		assert.Nil(t, err)
51		assert.Equal(t, expOutput, stdout.String())
52	})
53}