MCPcopy Create free account
hub / github.com/cli/cli / TestParseWriteArgs

Function TestParseWriteArgs

script/ghmock/gitcmd_test.go:100–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

98}
99
100func TestParseWriteArgs(t *testing.T) {
101 tests := []struct {
102 name string
103 args []string
104 want writeOptions
105 err string
106 }{
107 {name: "contents", args: []string{"main/a.txt", "--text", "one\n"}, want: writeOptions{path: "main/a.txt", text: "one\n"}},
108 {name: "empty file", args: []string{"empty", "--text", ""}, want: writeOptions{path: "empty"}},
109 {name: "missing text", args: []string{"empty"}, err: "pass --text with the file contents"},
110 {name: "outside workspace", args: []string{"../escape", "--text", "x"}, err: "pass a file path relative to the Git workspace"},
111 {name: "missing path", args: []string{"--text", "x"}, err: "pass a file path relative to the Git workspace"},
112 }
113 for _, tt := range tests {
114 t.Run(tt.name, func(t *testing.T) {
115 got, err := parseWriteArgs(tt.args)
116 if tt.err != "" {
117 require.EqualError(t, err, tt.err)
118 return
119 }
120 require.NoError(t, err)
121 assert.Equal(t, tt.want, got)
122 })
123 }
124}
125
126func TestCmdWrite(t *testing.T) {
127 tests := []struct {

Callers

nothing calls this directly

Calls 3

parseWriteArgsFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected