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 mock test for system operations on client side #1015

Merged
merged 1 commit into from
Apr 2, 2018
Merged

Conversation

ZouRui89
Copy link
Contributor

Signed-off-by: Zou Rui 21751189@zju.edu.cn

Ⅰ. Describe what this PR did

add all the mock for system operations on client side

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented Mar 30, 2018

Codecov Report

Merging #1015 into master will increase coverage by 0.27%.
The diff coverage is 92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1015      +/-   ##
==========================================
+ Coverage   14.91%   15.18%   +0.27%     
==========================================
  Files         133      135       +2     
  Lines        8483     8483              
==========================================
+ Hits         1265     1288      +23     
+ Misses       7118     7094      -24     
- Partials      100      101       +1
Impacted Files Coverage Δ
client/registry_login.go 100% <100%> (ø)
client/system_info.go 100% <100%> (ø)
client/system_ping.go 77.77% <77.77%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30c8277...53247a3. Read the comment docs.

@ZouRui89
Copy link
Contributor Author

PTAL @allencloud

@@ -30,11 +30,11 @@ func TestSystemVersion(t *testing.T) {
if !strings.HasPrefix(req.URL.Path, expectedURL) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
}
version := types.SystemVersion{
versionConfig := types.SystemVersion{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think this is a config, version is just OK for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The config stuff is only for post request, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, config is usually stored in the post request body. While this part of code is simulating a server which is returning a http response. And for this API, it returns types.SystemVersion.

"github.com/alibaba/pouch/apis/types"
)

// RegistryLogin requests a registry server to login.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is quite confusing. Could we change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

if !strings.HasPrefix(req.URL.Path, expectedURL) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
}
loginConfig := types.AuthConfig{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that in the test you input AuthConfig in client.RegistryLogin(context.Background(), &types.AuthConfig{Username: "user_name", Password: "123456"}). Why do you construct a new one in this place?

And actually this function would return a struct named AuthResponse, which is defined :

type AuthResponse struct {

	// An opaque token used to authenticate a user after a successful login
	IdentityToken string `json:"IdentityToken,omitempty"`

	// The status of the authentication
	// Required: true
	Status string `json:"Status"`
}

Please change this part. Thanks a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. I mixed the get request with post request again. Will change it ASAP.

@ZouRui89 ZouRui89 changed the title test: add more mock test on client side test: add mock test for system operations on client side Apr 2, 2018
@Letty5411
Copy link
Contributor

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Apr 2, 2018
// RegistryLogin authenticates the server with a given registry to login.
func (client *APIClient) RegistryLogin(ctx context.Context, auth *types.AuthConfig) (*types.AuthResponse, error) {
resp, err := client.post(ctx, "/auth", nil, auth, nil)
if err != nil || resp.StatusCode == http.StatusUnauthorized {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part has a potential logic bug which is already described in #1030.

HTTPCli: httpClient,
}

if infoRes, err := client.SystemInfo(context.Background()); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we assert values when err != nil? @ZouRui89

@allencloud
Copy link
Collaborator

not-LGTM, unless update the err judging.

Signed-off-by: Zou Rui <21751189@zju.edu.cn>
@allencloud
Copy link
Collaborator

LGTM

@allencloud allencloud merged commit 85d808d into AliyunContainerService:master Apr 2, 2018
@ZouRui89 ZouRui89 deleted the mock branch April 2, 2018 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/test LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants