Documentation
¶
Overview ¶
Package testutil provides testing utilities for Linear client tests.
This package provides two approaches for mocking Linear API calls in tests:
- GoQL Mock Server (graphql_test.Server): Higher-level mocking at the GraphQL operation level. Good for testing complete request/response cycles.
- Mock Transport (MockTransport): Lower-level mocking at the HTTP level. Good for fine-grained control over raw responses.
Example using mock transport:
mockResponse := `{"data": {"viewer": {"id": "123"}}}`
client := linear.NewClient("test-token")
client.GetBase().SetHTTPClient(&http.Client{Transport: testutil.NewSuccessTransport(mockResponse)})
Index ¶
- func NewLinearMockServer(t *testing.T) *graphql_test.Server
- func RegisterCommentCreateMutation(ts *graphql_test.Server, issueID string, body string, response interface{})
- func RegisterCreateIssueMutation(ts *graphql_test.Server, input map[string]interface{}, response interface{})
- func RegisterErrorResponse(ts *graphql_test.Server, operationName string, status int, err error)
- func RegisterIssueByIdentifierQuery(ts *graphql_test.Server, identifier string, issue interface{})
- func RegisterIssueQuery(ts *graphql_test.Server, issueID string, issue interface{})
- func RegisterIssuesQuery(ts *graphql_test.Server, filters map[string]interface{}, issues interface{})
- func RegisterReactionCreateMutation(ts *graphql_test.Server, issueID, emoji string, response interface{})
- func RegisterTeamsQuery(ts *graphql_test.Server, teams interface{})
- func RegisterUpdateIssueMutation(ts *graphql_test.Server, issueID string, input map[string]interface{}, ...)
- func RegisterViewerQuery(ts *graphql_test.Server, viewer interface{})
- type CommentCreateData
- type CommentCreateResult
- type GraphQLError
- type GraphQLResponse
- type IssueCreateData
- type IssueCreateResult
- type IssueData
- type IssueResponse
- type IssueUpdateData
- type IssueUpdateResult
- type IssuesData
- type IssuesNodes
- type MockTransport
- type PageInfo
- type ProjectInfo
- type ReactionCreateData
- type ReactionCreateResult
- type StateInfo
- type TeamInfo
- type TeamsData
- type TeamsNodes
- type UserInfo
- type ViewerData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLinearMockServer ¶
func NewLinearMockServer(t *testing.T) *graphql_test.Server
NewLinearMockServer creates a new GraphQL mock server for Linear tests. The server is automatically cleaned up when the test finishes.
func RegisterCommentCreateMutation ¶
func RegisterCommentCreateMutation(ts *graphql_test.Server, issueID string, body string, response interface{})
RegisterCommentCreateMutation registers a mock response for comment creation.
func RegisterCreateIssueMutation ¶
func RegisterCreateIssueMutation(ts *graphql_test.Server, input map[string]interface{}, response interface{})
RegisterCreateIssueMutation registers a mock response for issue creation.
func RegisterErrorResponse ¶
func RegisterErrorResponse(ts *graphql_test.Server, operationName string, status int, err error)
RegisterErrorResponse registers an error response for an operation.
func RegisterIssueByIdentifierQuery ¶
func RegisterIssueByIdentifierQuery(ts *graphql_test.Server, identifier string, issue interface{})
RegisterIssueByIdentifierQuery registers a mock response for an issue query by identifier.
func RegisterIssueQuery ¶
func RegisterIssueQuery(ts *graphql_test.Server, issueID string, issue interface{})
RegisterIssueQuery registers a mock response for an issue query.
func RegisterIssuesQuery ¶
func RegisterIssuesQuery(ts *graphql_test.Server, filters map[string]interface{}, issues interface{})
RegisterIssuesQuery registers a mock response for the issues query.
func RegisterReactionCreateMutation ¶
func RegisterReactionCreateMutation(ts *graphql_test.Server, issueID, emoji string, response interface{})
RegisterReactionCreateMutation registers a mock response for reaction creation.
func RegisterTeamsQuery ¶
func RegisterTeamsQuery(ts *graphql_test.Server, teams interface{})
RegisterTeamsQuery registers a mock response for the teams query.
func RegisterUpdateIssueMutation ¶
func RegisterUpdateIssueMutation(ts *graphql_test.Server, issueID string, input map[string]interface{}, response interface{})
RegisterUpdateIssueMutation registers a mock response for issue update.
func RegisterViewerQuery ¶
func RegisterViewerQuery(ts *graphql_test.Server, viewer interface{})
RegisterViewerQuery registers a mock response for the viewer query.
Types ¶
type CommentCreateData ¶
type CommentCreateData struct {
CommentCreate CommentCreateResult `json:"commentCreate"`
}
CommentCreateData wraps comment creation response.
type CommentCreateResult ¶
type CommentCreateResult struct {
Success bool `json:"success"`
Comment interface{} `json:"comment"`
}
CommentCreateResult contains comment creation result.
type GraphQLError ¶
type GraphQLError struct {
Message string `json:"message"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
GraphQLError represents a GraphQL error.
type GraphQLResponse ¶
type GraphQLResponse struct {
Data interface{} `json:"data,omitempty"`
Errors []GraphQLError `json:"errors,omitempty"`
}
GraphQLResponse is a helper for building GraphQL response bodies.
func NewGraphQLDataResponse ¶
func NewGraphQLDataResponse(data interface{}) GraphQLResponse
NewGraphQLDataResponse creates a successful GraphQL response with data.
func NewGraphQLErrorResponse ¶
func NewGraphQLErrorResponse(message, code string) GraphQLResponse
NewGraphQLErrorResponse creates a GraphQL error response.
type IssueCreateData ¶
type IssueCreateData struct {
IssueCreate IssueCreateResult `json:"issueCreate"`
}
IssueCreateData wraps issue creation response.
type IssueCreateResult ¶
type IssueCreateResult struct {
Success bool `json:"success"`
Issue interface{} `json:"issue"`
}
IssueCreateResult contains issue creation result.
type IssueData ¶
type IssueData struct {
Issue interface{} `json:"issue"`
}
IssueData wraps issue data for GraphQL responses.
type IssueResponse ¶
type IssueResponse struct {
ID string `json:"id"`
Identifier string `json:"identifier"`
Title string `json:"title"`
Description string `json:"description"`
State *StateInfo `json:"state,omitempty"`
Team *TeamInfo `json:"team,omitempty"`
Creator *UserInfo `json:"creator,omitempty"`
Assignee *UserInfo `json:"assignee,omitempty"`
Project *ProjectInfo `json:"project,omitempty"`
URL string `json:"url,omitempty"`
}
IssueResponse is a helper type for building issue mock responses.
func NewTestIssue ¶
func NewTestIssue(id, identifier, title string) IssueResponse
NewTestIssue creates a standard test issue response.
type IssueUpdateData ¶
type IssueUpdateData struct {
IssueUpdate IssueUpdateResult `json:"issueUpdate"`
}
IssueUpdateData wraps issue update response.
type IssueUpdateResult ¶
type IssueUpdateResult struct {
Success bool `json:"success"`
Issue interface{} `json:"issue"`
}
IssueUpdateResult contains issue update result.
type IssuesData ¶
type IssuesData struct {
Issues IssuesNodes `json:"issues"`
}
IssuesData wraps issues list data for GraphQL responses.
type IssuesNodes ¶
type IssuesNodes struct {
Nodes []interface{} `json:"nodes"`
PageInfo *PageInfo `json:"pageInfo,omitempty"`
}
IssuesNodes contains the nodes array for paginated results.
type MockTransport ¶
MockTransport implements http.RoundTripper for testing HTTP clients.
func NewMockTransport ¶
func NewMockTransport(statusCode int, body interface{}) *MockTransport
NewMockTransport creates a mock transport with a JSON response body.
func NewSuccessTransport ¶
func NewSuccessTransport(body interface{}) *MockTransport
NewSuccessTransport creates a mock transport with a 200 OK response.
type PageInfo ¶
type PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
EndCursor string `json:"endCursor,omitempty"`
}
PageInfo contains pagination information.
type ProjectInfo ¶
type ProjectInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
ProjectInfo represents project information.
type ReactionCreateData ¶
type ReactionCreateData struct {
ReactionCreate ReactionCreateResult `json:"reactionCreate"`
}
ReactionCreateData wraps reaction creation response.
type ReactionCreateResult ¶
type ReactionCreateResult struct {
Success bool `json:"success"`
Reaction interface{} `json:"reaction"`
}
ReactionCreateResult contains reaction creation result.
type StateInfo ¶
type StateInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
}
StateInfo represents workflow state information.
type TeamInfo ¶
TeamInfo represents team information.
func NewTestTeam ¶
NewTestTeam creates a standard test team response.
type TeamsData ¶
type TeamsData struct {
Teams TeamsNodes `json:"teams"`
}
TeamsData wraps teams data for GraphQL responses.
type TeamsNodes ¶
type TeamsNodes struct {
Nodes []interface{} `json:"nodes"`
}
TeamsNodes contains the nodes array for teams.
type UserInfo ¶
type UserInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email,omitempty"`
}
UserInfo represents user information.
func NewTestUser ¶
NewTestUser creates a standard test user response.
type ViewerData ¶
type ViewerData struct {
Viewer interface{} `json:"viewer"`
}
ViewerData wraps viewer data for GraphQL responses.