Skip to content

Commit

Permalink
Fix lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
hantonelli committed Mar 31, 2019
1 parent 73b3a53 commit 2c1f857
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions handler/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,20 @@ func processMultipart(r *http.Request, request *params, uploadMaxMemory int64) e
for key, path := range uploadsMap {
file, header, err := r.FormFile(key)
if err != nil {
return errors.New(fmt.Sprintf("failed to get key %s from form", key))
return fmt.Errorf("failed to get key %s from form", key)
}
upload = graphql.Upload{
File: file,
Size: header.Size,
Filename: header.Filename,
}
if len(path) != 1 || !strings.HasPrefix(path[0], "variables.") {
return errors.New(fmt.Sprintf("invalid value for key %s", key))
return fmt.Errorf("invalid value for key %s", key)
}
err = addUploadToOperations(operations, upload, path[0])
if err != nil {
return err
}
addUploadToOperations(operations, upload, path[0])
}

// set request variables
Expand Down Expand Up @@ -585,7 +588,7 @@ func addUploadToOperations(operations interface{}, upload graphql.Upload, path s
switch idx := p.(type) {
case string:
if operations == nil {
return errors.New(fmt.Sprintf("variables is missing, path: %s", path))
return fmt.Errorf("variables is missing, path: %s", path)
}
if last {
operations.(map[string]interface{})[idx] = upload
Expand All @@ -594,7 +597,7 @@ func addUploadToOperations(operations interface{}, upload graphql.Upload, path s
}
case int:
if operations == nil {
return errors.New(fmt.Sprintf("variables is missing, path: %s", path))
return fmt.Errorf("variables is missing, path: %s", path)
}
if last {
operations.([]interface{})[idx] = upload
Expand Down
3 changes: 3 additions & 0 deletions handler/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func TestAddUploadToOperations(t *testing.T) {

t.Run("fail missing all variables", func(t *testing.T) {
file, err := os.Open("path/to/file")
require.Nil(t, err)
var operations map[string]interface{}
upload := graphql.Upload{
File: file,
Expand All @@ -421,6 +422,7 @@ func TestAddUploadToOperations(t *testing.T) {
"file": nil,
},
}
require.Nil(t, err)

upload := graphql.Upload{
File: file,
Expand All @@ -443,6 +445,7 @@ func TestAddUploadToOperations(t *testing.T) {

t.Run("valid nested variable", func(t *testing.T) {
file, err := os.Open("path/to/file")
require.Nil(t, err)
operations := map[string]interface{}{
"variables": map[string]interface{}{
"req": []interface{}{
Expand Down
6 changes: 2 additions & 4 deletions handler/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ func (e *executableSchemaMock) Mutation(ctx context.Context, op *ast.OperationDe

func (e *executableSchemaMock) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {
return func() *graphql.Response {
select {
case <-ctx.Done():
return nil
}
<-ctx.Done()
return nil
}
}

0 comments on commit 2c1f857

Please sign in to comment.