Skip to content
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: add test cases for diskquota_test.go #2638

Merged
merged 1 commit into from
Jan 15, 2019

Conversation

hellolijj
Copy link
Contributor

Ⅰ. Describe what this PR did

test: add test cases for diskquota_test.go

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Dec 30, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@22bfd53). Click here to learn what that means.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2638   +/-   ##
=========================================
  Coverage          ?   43.38%           
=========================================
  Files             ?      277           
  Lines             ?    18720           
  Branches          ?        0           
=========================================
  Hits              ?     8121           
  Misses            ?     9353           
  Partials          ?     1246
Flag Coverage Δ
#criv1alpha1test 31.4% <0%> (?)
#criv1alpha2test 35.61% <0%> (?)
#nodee2etest 32.73% <0%> (?)
Impacted Files Coverage Δ
apis/opts/diskquota.go 0% <0%> (ø)

@@ -9,17 +9,21 @@ import (
func ParseDiskQuota(quotas []string) (map[string]string, error) {
var quotaMaps = make(map[string]string)

if quotas == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually quotas is a slice of string, then I think using len(quota) == 0 will be better. Since then it will cover two cases:

  • first, the slice is a nil;
  • second, the slice is not nil, but an empty slice.

WDYT? @hellolijj

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very good advise, i totally agree

@@ -9,17 +9,21 @@ import (
func ParseDiskQuota(quotas []string) (map[string]string, error) {
var quotaMaps = make(map[string]string)

if quotas == nil {
return nil, fmt.Errorf("invalid format for disk quota: %s", quotas)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to build PouchContainer a user-friendly, operator-friendly software, so when returning error we should try to make the error message be much clearer. For this case, operators can only get the error with the message invalid, but he has no idea why this is invalid.

Thus from my point of view, maybe fmt.Errorf("invalid format for disk quota: quotas cannot be empty", quotas) will be better. In addition, we try to make quotas to be formatted is meaningless, because it is already nil. WDYT? @hellolijj

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right!

for _, quota := range quotas {
if quota == "" {
if strings.TrimSpace(quota) == "" {
return nil, fmt.Errorf("invalid format for disk quota: %s", quota)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same problem, we should add more concrete invalid reason here.

case 2:
quotaMaps[parts[0]] = parts[1]
quotaMaps[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
default:
return nil, fmt.Errorf("invalid format for disk quota: %s", quota)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same problem, we should add more concrete invalid reason here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, how can i test the case like follow? for example, the quota is []string{"foo = foo"}}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could test this to be []string{"a=b=c"}, then it is invalid.

@@ -19,7 +19,7 @@ func TestParseDiskQuota(t *testing.T) {
{name: "test2", args: args{diskquota: []string{"foo=foo=foo"}}, want: nil, wantErr: true},
{name: "test3", args: args{diskquota: []string{"foo"}}, want: map[string]string{"/": "foo"}, wantErr: false},
{name: "test4", args: args{diskquota: []string{"foo=foo"}}, want: map[string]string{"foo": "foo"}, wantErr: false},
{name: "test5", args: args{diskquota: []string{"foo = foo"}}, want: map[string]string{"foo": "foo"}, wantErr: true},
{name: "test5", args: args{diskquota: []string{"foo= foo"}}, want: map[string]string{"foo": "foo"}, wantErr: false},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it had better to unify key=value format, for instance, to remove useless whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i thinks so.
So, do i delete this test case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be a test case, I think ParseDiskQuota should test it valid or invalid whether has space in string slice @hellolijj @chuanchang

@rudyfly
Copy link
Collaborator

rudyfly commented Jan 8, 2019

LGTM, but ci failed.

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Jan 8, 2019
fuweid
fuweid previously requested changes Jan 8, 2019
Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hellolijj please rebase with current master. thanks

@pouchrobot
Copy link
Collaborator

@hellolijj Thanks for your contribution. 🍻
Please sign off in each of your commits.

@hellolijj
Copy link
Contributor Author

I have rebase the code and force-pushed it. @fuweid please help me to review it again 😄

@allencloud allencloud merged commit 84f7aa6 into AliyunContainerService:master Jan 15, 2019
@hellolijj hellolijj deleted the test_case branch January 20, 2019 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/storage areas/test LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants