Lightweight and easily self-hostable Git forge. git.poy.ooo
git-forge selfhosting homebrew
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243package ssh
import "testing"
func TestParseGitCommand(t *testing.T) { tests := []struct { name string raw string wantCmd string wantArg string wantErr bool }{ {"upload pack", "git-upload-pack '~poyo/banana'", "git-upload-pack", "poyo/banana", false}, {"receive pack", "git-receive-pack '~poyo/banana'", "git-receive-pack", "poyo/banana", false}, {"upload archive", "git-upload-archive '~poyo/banana'", "git-upload-archive", "poyo/banana", false}, {"repo with dash", "git-upload-pack '~poyo/my-repo'", "git-upload-pack", "poyo/my-repo", false}, {"repo with dot", "git-upload-pack '~poyo/banana.git'", "git-upload-pack", "poyo/banana.git", false}, {"missing tilde", "git-upload-pack 'poyo/banana'", "", "", true}, {"leading slash", "git-upload-pack '/~poyo/banana'", "", "", true}, {"traversal", "git-upload-pack '~poyo/../banana'", "", "", true}, {"trailing garbage", "git-upload-pack '~poyo/banana' extra", "", "", true}, {"empty", "", "", "", true}, }
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := parseGitCommand(tt.raw) if tt.wantErr { if err == nil { t.Fatalf("parseGitCommand(%q) expected error, got %+v", tt.raw, got) } return } if err != nil { t.Fatalf("parseGitCommand(%q) unexpected error: %v", tt.raw, err) } if got.Command != tt.wantCmd || got.Args != tt.wantArg { t.Errorf("parseGitCommand(%q) = {%q, %q}, want {%q, %q}", tt.raw, got.Command, got.Args, tt.wantCmd, tt.wantArg) } }) }}