Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/content-service/pkg/git/porcelain_test.go
2500 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package git
6
7
import (
8
"bytes"
9
"testing"
10
11
"github.com/google/go-cmp/cmp"
12
)
13
14
func TestParsePorcelain(t *testing.T) {
15
tests := []struct {
16
Input string
17
Expectation *porcelainStatus
18
Error error
19
}{
20
{`# branch.oid e48df267d11a16a04101e3f503aef27f8352e7fb
21
# branch.head cw/git-status
22
1 .M N... 100644 100644 100644 9f8efaf877a34290b1ec672ea76ed23ae1f6fc0e 9f8efaf877a34290b1ec672ea76ed23ae1f6fc0e ../../client/wsready.d.ts
23
1 .M N... 100644 100644 100644 fecd2cb9388debfa8b55eff29042940c6b48e34f fecd2cb9388debfa8b55eff29042940c6b48e34f ../../client/wsdaemon_grpc_pb.d.ts
24
1 .M N... 100644 100644 100644 21d9ddf581bb8c76d4c57e751d6ca70f20d6d988 21d9ddf581bb8c76d4c57e751d6ca70f20d6d988 ../../client/wsdaemon_grpc_pb.js
25
1 .M N... 100644 100644 100644 0fdd088bb302577f8d9f7b1e24bf1982f1e0b339 0fdd088bb302577f8d9f7b1e24bf1982f1e0b339 ../../client/wsdaemon_pb.d.ts
26
1 .M N... 100644 100644 100644 5aebcbc6f8e2c400440b08e1ef9a8cf207121ba0 5aebcbc6f8e2c400440b08e1ef9a8cf207121ba0 ../../client/wsdaemon_pb.js
27
1 .M N... 100644 100644 100644 afb7787839a21a1c6ec96b11ac771966e6e59e27 afb7787839a21a1c6ec96b11ac771966e6e59e27 ../../go.mod
28
1 .M N... 100644 100644 100644 6e158cd7a2cddc9904ca4958bb2a919ef76aa93b 6e158cd7a2cddc9904ca4958bb2a919ef76aa93b ../../go.sum
29
1 .M N... 100644 100644 100644 59cbc1f794f8d0809985b8400824defc1812118a 59cbc1f794f8d0809985b8400824defc1812118a ../internal/session/workspace.go
30
1 .M N... 100644 100644 100644 33136abd6ca52574c44ce9dc4c6892ff1dc4747a 33136abd6ca52574c44ce9dc4c6892ff1dc4747a wsdaemon.pb.go
31
1 .M N... 100644 100644 100644 4108d304df5c42949c54b8b84dff7af06684ddcc 4108d304df5c42949c54b8b84dff7af06684ddcc wsdaemon.proto
32
1 .M N... 100644 100644 100644 d6ea4d281da87355dad7040893bf8b0328dc0c60 d6ea4d281da87355dad7040893bf8b0328dc0c60 ../syncd/service.go
33
? ../../../../foo`,
34
&porcelainStatus{
35
BranchOID: "e48df267d11a16a04101e3f503aef27f8352e7fb",
36
BranchHead: "cw/git-status",
37
UncommitedFiles: []string{
38
"../../client/wsready.d.ts",
39
"../../client/wsdaemon_grpc_pb.d.ts",
40
"../../client/wsdaemon_grpc_pb.js",
41
"../../client/wsdaemon_pb.d.ts",
42
"../../client/wsdaemon_pb.js",
43
"../../go.mod",
44
"../../go.sum",
45
"../internal/session/workspace.go",
46
"wsdaemon.pb.go",
47
"wsdaemon.proto",
48
"../syncd/service.go",
49
},
50
UntrackedFiles: []string{
51
"../../../../foo",
52
},
53
},
54
nil,
55
},
56
{`# branch.oid 68265e04346e5955f738765ef65fe51ae3602d9c
57
# branch.head master
58
# branch.upstream origin/master
59
# branch.ab +1 -0
60
? x
61
? a/b/c/d/e`,
62
&porcelainStatus{
63
BranchOID: "68265e04346e5955f738765ef65fe51ae3602d9c",
64
BranchHead: "master",
65
UntrackedFiles: []string{"x", "a/b/c/d/e"},
66
},
67
nil,
68
},
69
}
70
71
for _, test := range tests {
72
res, err := parsePorcelain(bytes.NewReader([]byte(test.Input)))
73
if err != test.Error {
74
t.Errorf("expected errors do not match: %v != %v", err, test.Error)
75
}
76
77
if diff := cmp.Diff(test.Expectation, res, cmp.AllowUnexported(porcelainStatus{})); diff != "" {
78
t.Errorf("unexpected result (-want +got):\n%s", diff)
79
}
80
}
81
}
82
83