Path: blob/main/components/content-service/pkg/git/porcelain_test.go
2500 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package git56import (7"bytes"8"testing"910"github.com/google/go-cmp/cmp"11)1213func TestParsePorcelain(t *testing.T) {14tests := []struct {15Input string16Expectation *porcelainStatus17Error error18}{19{`# branch.oid e48df267d11a16a04101e3f503aef27f8352e7fb20# branch.head cw/git-status211 .M N... 100644 100644 100644 9f8efaf877a34290b1ec672ea76ed23ae1f6fc0e 9f8efaf877a34290b1ec672ea76ed23ae1f6fc0e ../../client/wsready.d.ts221 .M N... 100644 100644 100644 fecd2cb9388debfa8b55eff29042940c6b48e34f fecd2cb9388debfa8b55eff29042940c6b48e34f ../../client/wsdaemon_grpc_pb.d.ts231 .M N... 100644 100644 100644 21d9ddf581bb8c76d4c57e751d6ca70f20d6d988 21d9ddf581bb8c76d4c57e751d6ca70f20d6d988 ../../client/wsdaemon_grpc_pb.js241 .M N... 100644 100644 100644 0fdd088bb302577f8d9f7b1e24bf1982f1e0b339 0fdd088bb302577f8d9f7b1e24bf1982f1e0b339 ../../client/wsdaemon_pb.d.ts251 .M N... 100644 100644 100644 5aebcbc6f8e2c400440b08e1ef9a8cf207121ba0 5aebcbc6f8e2c400440b08e1ef9a8cf207121ba0 ../../client/wsdaemon_pb.js261 .M N... 100644 100644 100644 afb7787839a21a1c6ec96b11ac771966e6e59e27 afb7787839a21a1c6ec96b11ac771966e6e59e27 ../../go.mod271 .M N... 100644 100644 100644 6e158cd7a2cddc9904ca4958bb2a919ef76aa93b 6e158cd7a2cddc9904ca4958bb2a919ef76aa93b ../../go.sum281 .M N... 100644 100644 100644 59cbc1f794f8d0809985b8400824defc1812118a 59cbc1f794f8d0809985b8400824defc1812118a ../internal/session/workspace.go291 .M N... 100644 100644 100644 33136abd6ca52574c44ce9dc4c6892ff1dc4747a 33136abd6ca52574c44ce9dc4c6892ff1dc4747a wsdaemon.pb.go301 .M N... 100644 100644 100644 4108d304df5c42949c54b8b84dff7af06684ddcc 4108d304df5c42949c54b8b84dff7af06684ddcc wsdaemon.proto311 .M N... 100644 100644 100644 d6ea4d281da87355dad7040893bf8b0328dc0c60 d6ea4d281da87355dad7040893bf8b0328dc0c60 ../syncd/service.go32? ../../../../foo`,33&porcelainStatus{34BranchOID: "e48df267d11a16a04101e3f503aef27f8352e7fb",35BranchHead: "cw/git-status",36UncommitedFiles: []string{37"../../client/wsready.d.ts",38"../../client/wsdaemon_grpc_pb.d.ts",39"../../client/wsdaemon_grpc_pb.js",40"../../client/wsdaemon_pb.d.ts",41"../../client/wsdaemon_pb.js",42"../../go.mod",43"../../go.sum",44"../internal/session/workspace.go",45"wsdaemon.pb.go",46"wsdaemon.proto",47"../syncd/service.go",48},49UntrackedFiles: []string{50"../../../../foo",51},52},53nil,54},55{`# branch.oid 68265e04346e5955f738765ef65fe51ae3602d9c56# branch.head master57# branch.upstream origin/master58# branch.ab +1 -059? x60? a/b/c/d/e`,61&porcelainStatus{62BranchOID: "68265e04346e5955f738765ef65fe51ae3602d9c",63BranchHead: "master",64UntrackedFiles: []string{"x", "a/b/c/d/e"},65},66nil,67},68}6970for _, test := range tests {71res, err := parsePorcelain(bytes.NewReader([]byte(test.Input)))72if err != test.Error {73t.Errorf("expected errors do not match: %v != %v", err, test.Error)74}7576if diff := cmp.Diff(test.Expectation, res, cmp.AllowUnexported(porcelainStatus{})); diff != "" {77t.Errorf("unexpected result (-want +got):\n%s", diff)78}79}80}818283