Skip to content

Commit

Permalink
Add unit tests for IsGoFile and TestTrimGoPath functions (#27)
Browse files Browse the repository at this point in the history
* Add IsGoFile test

* Add TestTrimGoPath
  • Loading branch information
flrnd authored and rodrigo-brito committed Oct 2, 2019
1 parent 42bf767 commit d2fb4dc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -53,3 +54,39 @@ func TestGetGithubBaseURL(t *testing.T) {
})
}
}

func TestIsGoFile(t *testing.T) {
tests := []struct {
got string
want bool
}{
{"foo.go", true},
{"bar.gol", false},
{"foobar", false},
{"fubar.g", false},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("given the filename %s", tt.got), func(t *testing.T) {
got := IsGoFile(tt.got)
assert.Equal(t, tt.want, got)
})
}
}

func TestTrimGoPath(t *testing.T) {
tests := []struct {
path string
repository string
want string
}{
{fmt.Sprintf("%s/src/gocity/main.go", os.Getenv("GOPATH")), "gocity", "/main.go"},
{fmt.Sprintf("%s/src/gocity/foo/bar.go", os.Getenv("GOPATH")), "gocity", "/foo/bar.go"},
{fmt.Sprintf("%s/src/gocity/vendor", os.Getenv("GOPATH")), "gocity", "/vendor"},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("given project %s/%s", tt.path, tt.repository), func(t *testing.T) {
got := TrimGoPath(tt.path, tt.repository)
assert.Equal(t, tt.want, got)
})
}
}

0 comments on commit d2fb4dc

Please sign in to comment.