-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: resultx ut #738
Merged
Merged
test: resultx ut #738
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package resultx | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
import ( | ||
"github.com/arana-db/arana/pkg/proto" | ||
) | ||
|
||
func TestEmptyResult(t *testing.T) { | ||
res := New() | ||
defer Drain(res) | ||
assert.Empty(t, res) | ||
dataset, err := res.Dataset() | ||
assert.NoError(t, err) | ||
assert.Empty(t, dataset) | ||
affected, err := res.RowsAffected() | ||
assert.NoError(t, err) | ||
assert.Equal(t, affected, uint64(0)) | ||
id, err := res.LastInsertId() | ||
assert.NoError(t, err) | ||
assert.Equal(t, id, uint64(0)) | ||
} | ||
|
||
func TestSlimResult(t *testing.T) { | ||
res := New(WithLastInsertID(1)) | ||
defer Drain(res) | ||
assert.NotEmpty(t, res) | ||
dataset, err := res.Dataset() | ||
assert.NoError(t, err) | ||
assert.Empty(t, dataset) | ||
affected, err := res.RowsAffected() | ||
assert.NoError(t, err) | ||
assert.Equal(t, affected, uint64(0)) | ||
id, err := res.LastInsertId() | ||
assert.NoError(t, err) | ||
assert.Equal(t, id, uint64(1)) | ||
} | ||
|
||
Comment on lines
+32
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 方便的话也加点注释吧,其实 Empty 和 Slim 是 Exec 的时候执行的,Empty 更像创表,等行为,Slim 像 insert,update等行为。 |
||
func TestFullResult(t *testing.T) { | ||
res := New(WithDataset(&utDataset{}), WithRowsAffected(1)) | ||
defer Drain(res) | ||
assert.NotEmpty(t, res) | ||
dataset, err := res.Dataset() | ||
assert.NoError(t, err) | ||
assert.Empty(t, dataset) | ||
affected, err := res.RowsAffected() | ||
assert.NoError(t, err) | ||
assert.Equal(t, affected, uint64(1)) | ||
id, err := res.LastInsertId() | ||
assert.NoError(t, err) | ||
assert.Equal(t, id, uint64(0)) | ||
} | ||
|
||
func TestDsResult(t *testing.T) { | ||
res := New(WithDataset(&utDataset{})) | ||
defer Drain(res) | ||
assert.NotEmpty(t, res) | ||
dataset, err := res.Dataset() | ||
assert.NoError(t, err) | ||
assert.Empty(t, dataset) | ||
affected, err := res.RowsAffected() | ||
assert.NoError(t, err) | ||
assert.Equal(t, affected, uint64(0)) | ||
id, err := res.LastInsertId() | ||
assert.NoError(t, err) | ||
assert.Equal(t, id, uint64(0)) | ||
} | ||
|
||
type utDataset struct{} | ||
|
||
func (cu *utDataset) Close() error { | ||
return nil | ||
} | ||
|
||
func (cu *utDataset) Fields() ([]proto.Field, error) { | ||
return nil, nil | ||
} | ||
|
||
func (cu *utDataset) Next() (proto.Row, error) { | ||
return nil, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加点异常case吧,比如有 ds 的时候,也有 InsertID 应该是什么返回。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个代码没法加异常呀,这个确定不了...,对这个不太懂,我理解的是这个覆盖率能达到就好