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

Start to add tests for modules/base/tool #90

Merged
merged 13 commits into from
Nov 8, 2016
Merged

Start to add tests for modules/base/tool #90

merged 13 commits into from
Nov 8, 2016

Conversation

metalmatze
Copy link
Contributor

I started to write some tests for modules/base/tool.
I'm going to add more tomorrow.

@codecov-io
Copy link

codecov-io commented Nov 6, 2016

Current coverage is 2.47% (diff: 100%)

Merging #90 into master will increase coverage by 0.28%

@@            master       #90   diff @@
========================================
  Files           31        32     +1   
  Lines         7508      7812   +304   
  Methods          0         0          
  Messages         0         0          
  Branches         0         0          
========================================
+ Hits           164       193    +29   
- Misses        7327      7601   +274   
- Partials        17        18     +1   

Powered by Codecov. Last update 9f437eb...10167b7

@andreynering andreynering added type/testing pr/wip This PR is not ready for review labels Nov 6, 2016
Copy link
Member

@bkcsoft bkcsoft left a comment

Choose a reason for hiding this comment

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

otherwise awesome work 😄

}

func TestShortSha(t *testing.T) {
if result := ShortSha("veryverylong"); result != "veryverylo" {
Copy link
Member

Choose a reason for hiding this comment

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

please use a hex-value when testing hash-functions 🙂

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 thought this was a hash-function too. But if you look closer it only shortens a string. Pretty bad function naming. But I don't want to change the API with the tests. That should be a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

until it's fixed, please use ShaSums ;)


func TestShortSha(t *testing.T) {
if result := ShortSha("veryverylong"); result != "veryverylo" {
t.Errorf("got the wrong sha1sum for string foobar: %s", result)
Copy link
Member

Choose a reason for hiding this comment

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

"wrong short sha1sum"?

// TODO: Test CreateTimeLimitCode()

func TestHashEmail(t *testing.T) {
if hash := HashEmail("lunny@gitea.io"); hash != "1b6d0c0e124d47ded12cd7115addeb11" {
Copy link
Member

Choose a reason for hiding this comment

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

I'd refrain against using real addresses when not necessary, this is why ’example.com’ exists 🙂

@tboerger tboerger added this to the 1.0.0 milestone Nov 7, 2016
@jbub
Copy link

jbub commented Nov 7, 2016

Hey @metalmatze, great work on adding tests, i have noticed that you are in some cases repeating and duplicating assert calls (for example TestTruncateString, TestFileSize or TestEllipsisString), you can remove some of the repetitions using table driven tests http://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go, in go 1.7 it can even speedup the tests by parallelizing them http://golang.rakyll.org/parallelize-test-tables/

setting.LibravatarService = libravatar.New()
assert.Equal(t,
"http://cdn.libravatar.org/avatar/353cbad9b58e69c96154ad99f92bedc7",
AvatarLink("gitea@example.com"),
Copy link
Member

Choose a reason for hiding this comment

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

If you need a test for a really federated avatar, try strk@kbt.io

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't make a difference for the test. right?

Copy link
Member

Choose a reason for hiding this comment

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

well, this one isn't really testing the federated part (I've seen packages just prefixing the hash with "cdn.libravatar.org" and be happy with it, it's not our case, we're actually doing the DNS lookups)

@metalmatze
Copy link
Contributor Author

Hey @jbub. Thanks for the hint.
It wasn't much work for me to duplicate those lines. Just a shortcut.
Parallelizing sounds pretty interesting though! 🚀

@metalmatze metalmatze changed the title WIP: Start to add tests for modules/base/tool Start to add tests for modules/base/tool Nov 7, 2016
@metalmatze metalmatze removed the pr/wip This PR is not ready for review label Nov 7, 2016
@metalmatze
Copy link
Contributor Author

I'm done for now. I think we could merge this and add more tests in another PR. This one is pretty big anyway. Updated all the stuff @bkcsoft said. 👍

LGTY? 😄

@codecov-io
Copy link

Current coverage is 3.14% (diff: 100%)

Merging #90 into master will increase coverage by 0.89%

@@            master       #90   diff @@
========================================
  Files           32        33     +1   
  Lines         7521      7821   +300   
  Methods          0         0          
  Messages         0         0          
  Branches         0         0          
========================================
+ Hits           169       246    +77   
- Misses        7335      7555   +220   
- Partials        17        20     +3   

Powered by Codecov. Last update 864d1b1...e74868a

@strk
Copy link
Member

strk commented Nov 8, 2016

LGTM

@andreynering
Copy link
Contributor

Awesome work, LGTM

@bkcsoft
Copy link
Member

bkcsoft commented Nov 8, 2016

LGTM

@bkcsoft bkcsoft merged commit 85b8b7f into go-gitea:master Nov 8, 2016
@metalmatze metalmatze deleted the feature/tool-tests branch November 8, 2016 09:39
@tboerger tboerger added the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Nov 29, 2016
lunny pushed a commit to lunny/gitea that referenced this pull request Feb 7, 2019
* Add an head ref for the sake of using self repo for testing

* Add test for CommitCount

* Add testing with git-1.7.2

* Add test for GetLatestCommitTime

The test checks that latest commit time is before now
and more recent than the commit this PR is based at
Test no error is raised by time parsing and GetLatestCommitTime
Print actual time when tests fail

* Accept git 1.7.2 as the minimum version

Debian old old (very old) distribution (6.0 aka Squeeze)
ships version 1.7.10.4.

The version requirement was raised in go-gitea#46 supposedly for the
need of "symbolic-ref" command, but that command is supported
by the 1.7.2 version too, and possibly even older versions.

* Reduce output from drone, add comments

Reduce steps, concatenating them in logical steps

* Interrupt step upon first failure

* Add Dockerfile for use with ci

* Use ad-hoc docker image for testing git-1.7.2

* Avoid running build/vet/clean twice

* Set HEAD ref also in testing-1-7 step
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants