Skip to content

Commit

Permalink
Add UT
Browse files Browse the repository at this point in the history
  • Loading branch information
voidint committed May 14, 2019
1 parent 4612826 commit b53de56
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ script:
- GO111MODULE=on GOOS=darwin go build
- GO111MODULE=on GOOS=windows go build
- GO111MODULE=on GOOS=linux go build
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
- go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
# - $GOPATH/bin/goveralls -service=travis-ci
- ./go.test.sh

after_success:
- bash <(curl -s https://codecov.io/bash)
18 changes: 18 additions & 0 deletions version/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package version

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"testing"

Expand Down Expand Up @@ -85,3 +87,19 @@ func TestAllVersions(t *testing.T) {
So(len(items), ShouldEqual, 66)
})
}

func TestURLUnreachableError(t *testing.T) {
Convey("URL不可达错误", t, func() {
url := "https://github.com/voidint"
core := errors.New("hello error")

err := NewURLUnreachableError(url, core)
So(err, ShouldNotBeNil)
e, ok := err.(*URLUnreachableError)
So(ok, ShouldBeTrue)
So(e, ShouldNotBeNil)
So(e.url, ShouldEqual, url)
So(e.err, ShouldEqual, core)
So(e.Error(), ShouldEqual, fmt.Sprintf("URL %q is unreachable ==> %s", url, core.Error()))
})
}
32 changes: 32 additions & 0 deletions version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package version

import (
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestFindVersion(t *testing.T) {
Convey("查找指定名称的版本", t, func() {
v0 := &Version{
Name: "1.12.5",
}
v1 := &Version{
Name: "1.11.10",
}
v2 := &Version{
Name: "1.9.7",
}

items := []*Version{v0, v1, v2}

v, err := FindVersion(items, "1.11.10")
So(err, ShouldBeNil)
So(v, ShouldNotBeNil)
So(v.Name, ShouldEqual, "1.11.10")

v, err = FindVersion(items, "1.11.11")
So(err, ShouldEqual, ErrVersionNotFound)
So(v, ShouldBeNil)
})
}

0 comments on commit b53de56

Please sign in to comment.