goc/tests/e2e/e2e_test.go

83 lines
2.7 KiB
Go
Raw Normal View History

2021-09-02 09:48:11 +00:00
/*
Copyright 2021 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.
*/
2021-07-22 11:57:56 +00:00
package e2e
import (
2021-07-23 03:17:53 +00:00
"time"
2021-07-22 11:57:56 +00:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("1 [基础测试]", func() {
var (
mgr *SamplesMgr
)
BeforeEach(func() {
mgr = NewSamplesMgr()
})
Describe("1 测试 build 命令", func() {
It("1.1.1 简单工程", func() {
dir, err := mgr.GetSampleByKey("basic")
Expect(err).To(BeNil(), "找不到 sample")
By("使用 goc build 命令编译")
2021-07-22 14:25:55 +00:00
_, err = RunShortRunCmd([]string{"goc", "build", "."}, dir, nil)
2021-07-22 11:57:56 +00:00
Expect(err).To(BeNil(), "goc build 运行错误")
2021-07-23 03:17:53 +00:00
By("检查代码是否被插入二进制")
contain, err := SearchSymbolInBinary(dir, "basic", "basic/goc-cover-agent-apis-auto-generated-11111-22222-package.loadFileCover")
Expect(err).To(BeNil(), "二进制检查失败")
Expect(contain).To(BeTrue(), "二进制中未找到插桩的符号")
2021-07-22 11:57:56 +00:00
})
})
Describe("2 测试 server 命令", func() {
2021-07-23 03:17:53 +00:00
It("1.2.1 测试编译/list/profile基础场景", func() {
dir, err := mgr.GetSampleByKey("basic2")
2021-07-22 11:57:56 +00:00
Expect(err).To(BeNil(), "找不到 sample")
By("启动 goc server")
2021-07-22 14:25:55 +00:00
lc := NewLongRunCmd([]string{"goc", "server", "."}, dir, nil)
2021-07-22 11:57:56 +00:00
lc.Run()
defer lc.Stop()
2021-07-23 03:17:53 +00:00
By("编译一个长时间运行的程序")
output, err := RunShortRunCmd([]string{"goc", "build", "."}, dir, nil)
Expect(err).To(BeNil(), "编译失败:"+output)
By("长时间运行 basic2")
basicC := NewLongRunCmd([]string{"./basic2"}, dir, nil)
basicC.Run()
defer basicC.Stop()
2021-07-22 11:57:56 +00:00
By("使用 goc list 获取服务列表")
2021-07-23 03:17:53 +00:00
output, err = RunShortRunCmd([]string{"goc", "list"}, dir, nil)
2021-07-22 11:57:56 +00:00
Expect(err).To(BeNil(), "goc list 运行错误")
2021-07-23 03:17:53 +00:00
Expect(output).To(ContainSubstring("127.0.0.1 ./basic2"), "goc list 输出应该包含 basic 服务")
By("使用 goc profile 获取覆盖率")
profileStr := `mode: count
basic2/main.go:8.13,9.6 1 1
basic2/main.go:9.6,12.3 2 2`
time.Sleep(time.Second)
output, err = RunShortRunCmd([]string{"goc", "profile"}, dir, nil)
Expect(err).To(BeNil(), "goc profile 运行错误")
Expect(output).To(ContainSubstring(profileStr), "goc profile 获取的覆盖率有误")
2021-07-22 11:57:56 +00:00
})
})
})