diff --git a/example/fileupload/fileupload_test.go b/example/fileupload/fileupload_test.go index a028d14a52a..2cda68f4360 100644 --- a/example/fileupload/fileupload_test.go +++ b/example/fileupload/fileupload_test.go @@ -109,12 +109,14 @@ func TestFileUpload(t *testing.T) { resolver := &Resolver{ MultipleUploadFunc: func(ctx context.Context, files []graphql.Upload) ([]model.File, error) { require.Len(t, files, 2) + var contents []string for i := range files { require.NotNil(t, files[i].File) content, err := ioutil.ReadAll(files[i].File) require.Nil(t, err) - require.Equal(t, string(content), "test") + contents = append(contents, string(content)) } + require.ElementsMatch(t, []string{"test1", "test2"}, contents) return []model.File{ {ID: 1}, {ID: 2}, @@ -132,11 +134,11 @@ func TestFileUpload(t *testing.T) { require.NoError(t, err) w0, err := bodyWriter.CreateFormFile("0", "a.txt") require.NoError(t, err) - _, err = w0.Write([]byte("test")) + _, err = w0.Write([]byte("test1")) require.NoError(t, err) w1, err := bodyWriter.CreateFormFile("1", "b.txt") require.NoError(t, err) - _, err = w1.Write([]byte("test")) + _, err = w1.Write([]byte("test2")) require.NoError(t, err) err = bodyWriter.Close() require.NoError(t, err) diff --git a/handler/graphql_test.go b/handler/graphql_test.go index ee709162734..0e8ca298049 100644 --- a/handler/graphql_test.go +++ b/handler/graphql_test.go @@ -155,14 +155,14 @@ func TestFileUpload(t *testing.T) { }) t.Run("valid single file upload with payload", func(t *testing.T) { - stub := &executableSchemaMock{ + mock := &executableSchemaMock{ MutationFunc: func(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { require.Equal(t, len(op.VariableDefinitions), 1) require.Equal(t, op.VariableDefinitions[0].Variable, "req") return &graphql.Response{Data: []byte(`{"singleUploadWithPayload":{"id":1}}`)} }, } - handler := GraphQL(stub) + handler := GraphQL(mock) bodyBuf := &bytes.Buffer{} bodyWriter := multipart.NewWriter(bodyBuf) @@ -206,11 +206,11 @@ func TestFileUpload(t *testing.T) { require.NoError(t, err) w0, err := bodyWriter.CreateFormFile("0", "a.txt") require.NoError(t, err) - _, err = w0.Write([]byte("test")) + _, err = w0.Write([]byte("test1")) require.NoError(t, err) w1, err := bodyWriter.CreateFormFile("1", "b.txt") require.NoError(t, err) - _, err = w1.Write([]byte("test")) + _, err = w1.Write([]byte("test2")) require.NoError(t, err) err = bodyWriter.Close() require.NoError(t, err) @@ -243,11 +243,11 @@ func TestFileUpload(t *testing.T) { require.NoError(t, err) w0, err := bodyWriter.CreateFormFile("0", "a.txt") require.NoError(t, err) - _, err = w0.Write([]byte("test")) + _, err = w0.Write([]byte("test1")) require.NoError(t, err) w1, err := bodyWriter.CreateFormFile("1", "b.txt") require.NoError(t, err) - _, err = w1.Write([]byte("test")) + _, err = w1.Write([]byte("test2")) require.NoError(t, err) err = bodyWriter.Close() require.NoError(t, err)