add test for internal package
add codecov configuration delete
This commit is contained in:
parent
0efacf0ca9
commit
735dbb078f
@ -88,3 +88,32 @@ func TestBuildBinaryName(t *testing.T) {
|
|||||||
cnt = strings.Count(string(out), "GoCover")
|
cnt = strings.Count(string(out), "GoCover")
|
||||||
assert.Equal(t, cnt > 0, true, "GoCover varibale should be in the binary")
|
assert.Equal(t, cnt > 0, true, "GoCover varibale should be in the binary")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test if goc can get variables in internal package
|
||||||
|
func TestBuildBinaryForInternalPackage(t *testing.T) {
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
|
workingDir := filepath.Join(baseDir, "../tests/samples/simple_project_with_internal")
|
||||||
|
gopath := ""
|
||||||
|
|
||||||
|
os.Setenv("GOPATH", gopath)
|
||||||
|
os.Setenv("GO111MODULE", "on")
|
||||||
|
|
||||||
|
buildFlags, buildOutput = "", ""
|
||||||
|
args := []string{"."}
|
||||||
|
runBuild(args, workingDir)
|
||||||
|
|
||||||
|
obj := filepath.Join(workingDir, "simple-project")
|
||||||
|
fInfo, err := os.Lstat(obj)
|
||||||
|
assert.Equal(t, err, nil, "the binary should be generated.")
|
||||||
|
assert.Equal(t, startTime.Before(fInfo.ModTime()), true, obj+"new binary should be generated, not the old one")
|
||||||
|
|
||||||
|
cmd := exec.Command("go", "tool", "objdump", "simple-project")
|
||||||
|
cmd.Dir = workingDir
|
||||||
|
out, _ := cmd.CombinedOutput()
|
||||||
|
cnt := strings.Count(string(out), "GoCacheCover")
|
||||||
|
assert.Equal(t, cnt > 0, true, "GoCacheCover variable for internal package should be in the binary")
|
||||||
|
|
||||||
|
cnt = strings.Count(string(out), "internal.GoCover")
|
||||||
|
assert.Equal(t, cnt > 0, true, "internal.GoCover varibale should be in the binary")
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ package cover
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -342,3 +343,30 @@ func TestListPackagesForSimpleModProject(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test if goc can get variables in internal package
|
||||||
|
func TestCoverResultForInternalPackage(t *testing.T) {
|
||||||
|
|
||||||
|
workingDir := "../../tests/samples/simple_project_with_internal"
|
||||||
|
gopath := ""
|
||||||
|
|
||||||
|
os.Setenv("GOPATH", gopath)
|
||||||
|
os.Setenv("GO111MODULE", "on")
|
||||||
|
|
||||||
|
testDir := filepath.Join(os.TempDir(), "goc-build-test")
|
||||||
|
copy.Copy(workingDir, testDir)
|
||||||
|
|
||||||
|
Execute("", gopath, testDir, "count", "", "http://127.0.0.1:7777")
|
||||||
|
|
||||||
|
_, err := os.Lstat(filepath.Join(testDir, "http_cover_apis_auto_generated.go"))
|
||||||
|
if !assert.Equal(t, err, nil) {
|
||||||
|
assert.FailNow(t, "should generate http_cover_apis_auto_generated.go")
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := ioutil.ReadFile(filepath.Join(testDir, "http_cover_apis_auto_generated.go"))
|
||||||
|
cnt := strings.Count(string(out), "GoCacheCover")
|
||||||
|
assert.Equal(t, cnt > 0, true, "GoCacheCover variable should be in http_cover_apis_auto_generated.go")
|
||||||
|
|
||||||
|
cnt = strings.Count(string(out), "example.com/simple-project/internal/foo.go")
|
||||||
|
assert.Equal(t, cnt > 0, true, "`example.com/simple-project/internal/foo.go` should be in http_cover_apis_auto_generated.go")
|
||||||
|
}
|
||||||
|
3
tests/samples/simple_project_with_internal/go.mod
Normal file
3
tests/samples/simple_project_with_internal/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module example.com/simple-project
|
||||||
|
|
||||||
|
go 1.11
|
@ -0,0 +1,7 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func Hello() {
|
||||||
|
fmt.Println("hello, world.")
|
||||||
|
}
|
7
tests/samples/simple_project_with_internal/main.go
Normal file
7
tests/samples/simple_project_with_internal/main.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "example.com/simple-project/internal"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
internal.Hello()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user