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

x/pkgsite: add tests for frontend.LatestVersion #40107

Open
julieqiu opened this issue Jul 7, 2020 · 3 comments
Open

x/pkgsite: add tests for frontend.LatestVersion #40107

julieqiu opened this issue Jul 7, 2020 · 3 comments

Comments

@julieqiu
Copy link
Contributor

@julieqiu julieqiu commented Jul 7, 2020

Add tests for frontend.latestVersion, which is used to return the latest version of a path.

@vikramcse
Copy link

@vikramcse vikramcse commented Jul 9, 2020

@julieqiu I would like to work on this issue. can I pick this?

@julieqiu
Copy link
Contributor Author

@julieqiu julieqiu commented Jul 9, 2020

Please do!

@vikramcse
Copy link

@vikramcse vikramcse commented Jul 11, 2020

@julieqiu I have gone through TestServer test from server_test.go file. I am thinking to write the test cases for latestVersion in similar way.

1. testCases := []serverTestCase{
		{
			name:           "module packages tab latest version",
			urlPath:        fmt.Sprintf("/mod/%s?tab=packages", sample.ModulePath),
			wantStatusCode: http.StatusOK,
			// Fall back to the latest version.
			want: in("",
				in("div.DetailsHeader-version", text("v1.0.0"))),
		},
	}
  1. insertTestModules()
  2. create a server i.e s = NewServer()
  3. create a middeware middleware.LatestVersion(s.LatestVersion) as s.LatestVersion is intended to be a parameter of middleware.LatestVersion
  4. call latestVersion method i.e s.latestVersion(context.Background(), packagePath, modulePath, pageType)
6. for _, tc := range testCases {
		a. create a httptest.NewRecorder()
		b. create a new httptest request to the urlPath
		c. parse the res.Body
		d. here in res.Body we can check compare the `requested` and `want` version
	}

Before moving forward with this solution, can you please let me know that is this the right approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.