goc build goc

update

update

update

update

update

update

update

update

update

update

update

update

update

update

update

update
This commit is contained in:
lyyyuna 2020-07-10 21:49:10 +08:00
parent 2535a6eb7c
commit 590461c281
8 changed files with 75 additions and 217 deletions

View File

@ -22,21 +22,19 @@ jobs:
- name: Go build
run: |
go build
- name: Go build test binary
- name: Use goc to build self
run: |
cd tests/e2e
go get -u github.com/onsi/ginkgo/ginkgo
ginkgo build ./...
- name: Upload binary result for job 1
./goc build --output ./gocc --debug
- name: Upload goc binary
uses: actions/upload-artifact@v2
with:
name: goc
path: goc
- name: Upload binary result for job 1
- name: Upload covered self goc binary
uses: actions/upload-artifact@v2
with:
name: e2e.test
path: tests/e2e/e2e.test
name: gocc
path: gocc
job_2:
name: E2E test
@ -56,7 +54,16 @@ jobs:
uses: actions/download-artifact@v2
with:
path: /home/runner/tools
- name: Install bats-core
run: |
git clone https://github.com/bats-core/bats-core.git
cd bats-core
sudo ./install.sh /usr/local
- name: Do test
run: |
chmod +x /home/runner/tools/goc/goc
export PATH=/home/runner/tools/goc:$PATH
chmod +x /home/runner/tools/gocc/gocc
export PATH=/home/runner/tools/gocc:$PATH
cd tests
./run-ci-actions.sh

3
go.mod
View File

@ -9,8 +9,6 @@ require (
github.com/julienschmidt/httprouter v1.2.0
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
github.com/otiai10/copy v1.0.2
github.com/qiniu/api.v7/v7 v7.5.0
github.com/sirupsen/logrus v1.6.0
@ -21,6 +19,5 @@ require (
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/tools v0.0.0-20200329025819-fd4102a86c65
k8s.io/kubernetes v1.13.0
k8s.io/test-infra v0.0.0-20200511080351-8ac9dbfab055
)

6
go.sum
View File

@ -59,6 +59,7 @@ github.com/Azure/go-autorest/autorest/validation v0.1.0/go.mod h1:Ha3z/SqBeaalWQ
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88=
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
@ -373,6 +374,7 @@ github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsC
github.com/googleapis/gnostic v0.2.2/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/csrf v1.6.2/go.mod h1:7tSf8kmjNYr7IWDCYhd3U8Ck34iQ/Yw5CJu7bAkHEGI=
@ -445,6 +447,7 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
@ -461,6 +464,7 @@ github.com/klauspost/pgzip v1.2.1/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQ
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@ -655,9 +659,11 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=

View File

@ -115,6 +115,15 @@ func (b *Build) determineOutputDir(outputDir string) (string, error) {
return "", fmt.Errorf("can only be called after Build.MvProjectsToTmp(): %w", ErrWrongCallSequence)
}
// fix #43
if outputDir != "" {
abs, err := filepath.Abs(outputDir)
if err != nil {
log.Errorf("Fail to transform the path: %v to absolute path: %v", outputDir, err)
return "", err
}
return abs, nil
}
// fix #43
// use target name from `go list -json ./...` of the main module
targetName := ""

View File

@ -1,29 +0,0 @@
/*
Copyright 2020 Qiniu Cloud (qiniu.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestE2e(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "E2E goc Suite")
}

View File

@ -1,168 +0,0 @@
/*
Copyright 2020 Qiniu Cloud (qiniu.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e_test
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/qiniu/goc/pkg/build"
)
var TESTS_ROOT string
var _ = BeforeSuite(func() {
TESTS_ROOT, _ = os.Getwd()
By("Current working directory: " + TESTS_ROOT)
TESTS_ROOT = filepath.Join(TESTS_ROOT, "..")
})
var _ = Describe("E2E", func() {
var GOPATH string
BeforeEach(func() {
GOPATH = os.Getenv("GOPATH")
// in GitHub Action, this value is empty
if GOPATH == "" {
GOPATH = filepath.Join(os.Getenv("HOME"), "go")
}
})
Context("Go module", func() {
It("Simple project", func() {
startTime := time.Now()
By("goc build")
testProjDir := filepath.Join(TESTS_ROOT, "samples/simple_project")
cmd := exec.Command("goc", "build", "--debug")
cmd.Dir = testProjDir
cmd.Env = append(os.Environ(), "GO111MODULE=on")
out, err := cmd.CombinedOutput()
Expect(err).To(BeNil(), "goc build on this project should be successful", string(out))
By("goc install")
testProjDir = filepath.Join(TESTS_ROOT, "samples/simple_project")
cmd = exec.Command("goc", "install", "--debug")
cmd.Dir = testProjDir
out, err = cmd.CombinedOutput()
Expect(err).To(BeNil(), "goc install on this project should be successful", string(out))
By("check files in generated temporary directory")
tempDir := filepath.Join(os.TempDir(), build.TmpFolderName(testProjDir))
_, err = os.Lstat(tempDir)
Expect(err).To(BeNil(), "projects should be copied to temporary directory")
By("check if cover variables are injected")
_, err = os.Lstat(filepath.Join(tempDir, "http_cover_apis_auto_generated.go"))
Expect(err).To(BeNil(), "a http server file should be generated")
By("check generated binary")
objects := []string{GOPATH + "/bin", testProjDir}
for _, dir := range objects {
obj := filepath.Join(dir, "simple-project")
fInfo, err := os.Lstat(obj)
Expect(err).To(BeNil())
Expect(startTime.Before(fInfo.ModTime())).To(Equal(true), obj+"new binary should be generated, not the old one")
cmd := exec.Command("go", "tool", "objdump", "simple-project")
cmd.Dir = dir
out, err = cmd.CombinedOutput()
Expect(err).To(BeNil(), "the binary cannot be disassembled")
cnt := strings.Count(string(out), "GoCover")
Expect(cnt).To(BeNumerically(">", 0), "GoCover variable should be in the binary")
cnt = strings.Count(string(out), "main.registerSelf")
Expect(cnt).To(BeNumerically(">", 0), "main.registerSelf function should be in the binary")
}
})
})
Context("GOPATH", func() {
var GOPATH string
BeforeEach(func() {
GOPATH = os.Getenv("GOPATH")
})
It("Simple GOPATH project", func() {
startTime := time.Now()
testProjDir := filepath.Join(TESTS_ROOT, "samples/simple_gopath_project")
oriWorkingDir := filepath.Join(testProjDir, "src/qiniu.com/simple_gopath_project")
GOPATH = testProjDir
By("goc build")
cmd := exec.Command("goc", "build", "--debug")
cmd.Dir = oriWorkingDir
// use GOPATH mode to compile project
cmd.Env = append(os.Environ(), fmt.Sprintf("GOPATH=%v", GOPATH), "GO111MODULE=off")
out, err := cmd.CombinedOutput()
fmt.Println(string(out))
Expect(err).To(BeNil(), "goc build on this project should be successful", string(out), cmd.Dir)
By("goc install")
testProjDir = filepath.Join(TESTS_ROOT, "samples/simple_gopath_project")
cmd = exec.Command("goc", "install", "--debug")
cmd.Dir = filepath.Join(testProjDir, "src/qiniu.com/simple_gopath_project")
// use GOPATH mode to compile project
cmd.Env = append(os.Environ(), fmt.Sprintf("GOPATH=%v", testProjDir), "GO111MODULE=off")
out, err = cmd.CombinedOutput()
Expect(err).To(BeNil(), "goc install on this project should be successful", string(out))
By("check files in generated temporary directory")
tempDir := filepath.Join(os.TempDir(), build.TmpFolderName(oriWorkingDir))
_, err = os.Lstat(tempDir)
Expect(err).To(BeNil(), "projects should be copied to temporary directory")
By("check if cover variables are injected")
newWorkingDir := filepath.Join(tempDir, "src/qiniu.com/simple_gopath_project")
_, err = os.Lstat(filepath.Join(newWorkingDir, "http_cover_apis_auto_generated.go"))
Expect(err).To(BeNil(), "a http server file should be generated")
By("check generated binary")
objects := []string{GOPATH + "/bin", oriWorkingDir}
for _, dir := range objects {
obj := filepath.Join(dir, "simple_gopath_project")
fInfo, err := os.Lstat(obj)
Expect(err).To(BeNil())
Expect(startTime.Before(fInfo.ModTime())).To(Equal(true), "new binary should be generated, not the old one")
cmd := exec.Command("go", "tool", "objdump", "simple_gopath_project")
cmd.Dir = dir
out, err = cmd.CombinedOutput()
Expect(err).To(BeNil(), "the binary cannot be disassembled")
cnt := strings.Count(string(out), "GoCover")
Expect(cnt).To(BeNumerically(">", 0), "GoCover variable should be in the binary")
cnt = strings.Count(string(out), "main.registerSelf")
Expect(cnt).To(BeNumerically(">", 0), "main.registerSelf function should be in the binary")
}
})
})
})

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2020 Qiniu Cloud (七牛云)
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -13,13 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
echo "test start"
chmod +x /home/runner/tools/goc/goc
export PATH=/home/runner/tools/goc:$PATH
bats server.bats
chmod +x /home/runner/tools/e2e.test/e2e.test
export PATH=/home/runner/tools/e2e.test:$PATH
cd e2e
e2e.test -test.v ./...
bash <(curl -s https://codecov.io/bash) -f filtered.cov -F e2e

41
tests/server.bats Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env bats
# Copyright 2020 Qiniu Cloud (七牛云)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
setup_file() {
# run centered server
goc server 3>&- &
GOC_PID=$!
sleep 2
# run covered goc
gocc server --port=:60001 3>&- &
GOCC_PID=$!
echo "goc gocc server started"
}
teardown_file() {
# collect from center
goc profile --debug -o filtered.cov
kill -9 $GOC_PID
kill -9 $GOCC_PID
}
@test "test basic goc server" {
# connect to covered goc
run goc clear --center=http://127.0.0.1:60001
[ "$status" -eq 0 ]
# connect to covered goc
run goc profile --center=http://127.0.0.1:60001
[ "$status" -eq 0 ]
}