MCPcopy
hub / github.com/github/github-mcp-server / TestGitHubErrorContext

Function TestGitHubErrorContext

pkg/errors/error_test.go:15–365  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestGitHubErrorContext(t *testing.T) {
16 t.Run("API errors can be added to context and retrieved", func(t *testing.T) {
17 // Given a context with GitHub error tracking enabled
18 ctx := ContextWithGitHubErrors(context.Background())
19
20 // Create a mock GitHub response
21 resp := &github.Response{
22 Response: &http.Response{
23 StatusCode: 404,
24 Status: "404 Not Found",
25 },
26 }
27 originalErr := fmt.Errorf("resource not found")
28
29 // When we add an API error to the context
30 updatedCtx, err := NewGitHubAPIErrorToCtx(ctx, "failed to fetch resource", resp, originalErr)
31 require.NoError(t, err)
32
33 // Then we should be able to retrieve the error from the updated context
34 apiErrors, err := GetGitHubAPIErrors(updatedCtx)
35 require.NoError(t, err)
36 require.Len(t, apiErrors, 1)
37
38 apiError := apiErrors[0]
39 assert.Equal(t, "failed to fetch resource", apiError.Message)
40 assert.Equal(t, resp, apiError.Response)
41 assert.Equal(t, originalErr, apiError.Err)
42 assert.Equal(t, "failed to fetch resource: resource not found", apiError.Error())
43 })
44
45 t.Run("GraphQL errors can be added to context and retrieved", func(t *testing.T) {
46 // Given a context with GitHub error tracking enabled
47 ctx := ContextWithGitHubErrors(context.Background())
48
49 originalErr := fmt.Errorf("GraphQL query failed")
50
51 // When we add a GraphQL error to the context
52 graphQLErr := newGitHubGraphQLError("failed to execute mutation", originalErr)
53 updatedCtx, err := addGitHubGraphQLErrorToContext(ctx, graphQLErr)
54 require.NoError(t, err)
55
56 // Then we should be able to retrieve the error from the updated context
57 gqlErrors, err := GetGitHubGraphQLErrors(updatedCtx)
58 require.NoError(t, err)
59 require.Len(t, gqlErrors, 1)
60
61 gqlError := gqlErrors[0]
62 assert.Equal(t, "failed to execute mutation", gqlError.Message)
63 assert.Equal(t, originalErr, gqlError.Err)
64 assert.Equal(t, "failed to execute mutation: GraphQL query failed", gqlError.Error())
65 })
66
67 t.Run("Raw API errors can be added to context and retrieved", func(t *testing.T) {
68 // Given a context with GitHub error tracking enabled
69 ctx := ContextWithGitHubErrors(context.Background())
70
71 // Create a mock HTTP response
72 resp := &http.Response{

Callers

nothing calls this directly

Calls 13

ContextWithGitHubErrorsFunction · 0.85
NewGitHubAPIErrorToCtxFunction · 0.85
GetGitHubAPIErrorsFunction · 0.85
newGitHubGraphQLErrorFunction · 0.85
GetGitHubGraphQLErrorsFunction · 0.85
newGitHubRawAPIErrorFunction · 0.85
addRawAPIErrorToContextFunction · 0.85
GetGitHubRawAPIErrorsFunction · 0.85

Tested by

no test coverage detected