Skip to content

Commit b11095f

Browse files
committed
add client_name to request
1 parent d66352e commit b11095f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ func main() {
171171
// HTTP Request
172172
//----------------------------------------------------------------------
173173
payload, err := json.Marshal(map[string]string{
174-
"query": query,
175-
"version": version,
176-
"language": "en",
174+
"query": query,
175+
"version": version,
176+
"language": "en",
177+
"client_name": "gh-ask-docs",
177178
})
178179
if err != nil {
179180
askdocs.Fatal(err)

main_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ func TestHTTPPayloadCreation(t *testing.T) {
165165
for _, tt := range tests {
166166
t.Run(tt.name, func(t *testing.T) {
167167
payload, err := json.Marshal(map[string]string{
168-
"query": tt.query,
169-
"version": tt.version,
170-
"language": "en",
168+
"query": tt.query,
169+
"version": tt.version,
170+
"language": "en",
171+
"client_name": "gh-ask-docs",
171172
})
172173
if err != nil {
173174
t.Fatalf("Failed to create payload: %v", err)
@@ -190,6 +191,10 @@ func TestHTTPPayloadCreation(t *testing.T) {
190191
if parsed["language"] != "en" {
191192
t.Errorf("Language = %q, want %q", parsed["language"], "en")
192193
}
194+
195+
if parsed["client_name"] != "gh-ask-docs" {
196+
t.Errorf("Client name = %q, want %q", parsed["client_name"], "gh-ask-docs")
197+
}
193198
})
194199
}
195200
}
@@ -309,9 +314,10 @@ func TestNDJSONResponseParsing(t *testing.T) {
309314

310315
func TestHTTPRequestCreation(t *testing.T) {
311316
payload, _ := json.Marshal(map[string]string{
312-
"query": "test query",
313-
"version": "free-pro-team@latest",
314-
"language": "en",
317+
"query": "test query",
318+
"version": "free-pro-team@latest",
319+
"language": "en",
320+
"client_name": "gh-ask-docs",
315321
})
316322

317323
req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewReader(payload))
@@ -429,9 +435,10 @@ func TestMockHTTPServer(t *testing.T) {
429435

430436
// Test making a request to our mock server
431437
payload, _ := json.Marshal(map[string]string{
432-
"query": "What is GitHub?",
433-
"version": "free-pro-team@latest",
434-
"language": "en",
438+
"query": "What is GitHub?",
439+
"version": "free-pro-team@latest",
440+
"language": "en",
441+
"client_name": "gh-ask-docs",
435442
})
436443

437444
req, _ := http.NewRequest(http.MethodPost, server.URL, bytes.NewReader(payload))

0 commit comments

Comments
 (0)