Merge pull request #110 from tongjingran/109

Error returned when no profiles fetched
This commit is contained in:
qiniu-bot 2020-09-16 10:38:12 +08:00 committed by GitHub
commit 5786eaa75d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 11 deletions

View File

@ -59,7 +59,7 @@ goc profile --force
}
res, err := cover.NewWorker(center).Profile(p)
if err != nil {
log.Fatalf("call host %v failed, err: %v, response: %v", center, err, string(res))
log.Fatalf("Goc server %v return an error: %v", center, err)
}
if output == "" {

View File

@ -75,46 +75,51 @@ func TestClientAction(t *testing.T) {
expectedErr: true,
},
{
name: "valid test with no service flag provied",
name: "valid test with no service flag provide",
service: Service{Name: "serviceOK", Address: profileSuccessMockSvr.URL},
param: ProfileParam{},
expected: "mockService/main.go:30.13,48.33 13 1",
},
{
name: "valid test with service flag provied",
name: "valid test with service flag provide",
service: Service{Name: "serviceOK", Address: profileSuccessMockSvr.URL},
param: ProfileParam{Service: []string{"serviceOK"}},
expected: "mockService/main.go:30.13,48.33 13 1",
},
{
name: "valid test with address flag provied",
name: "valid test with address flag provide",
service: Service{Name: "serviceOK", Address: profileSuccessMockSvr.URL},
param: ProfileParam{Address: []string{profileSuccessMockSvr.URL}},
expected: "mockService/main.go:30.13,48.33 13 1",
},
{
name: "invalid test with invalid service flag provide",
service: Service{Name: "serviceOK", Address: profileSuccessMockSvr.URL},
param: ProfileParam{Service: []string{"unknown"}},
expected: "service [unknown] not found",
expectedErr: true,
},
{
name: "invalid test with invalid profile got by service",
service: Service{Name: "serviceErr", Address: profileErrMockSvr.URL},
expected: "bad mode line: error",
expectedErr: true,
},
{
name: "invalid test with disconnected service",
service: Service{Name: "serviceNotExist", Address: "http://172.0.0.2:7777"},
expected: "connection refused",
expectedErr: true,
},
{
service: Service{Name: "serviceNotExist", Address: "http://172.0.0.2:7777"},
param: ProfileParam{Force: true},
expected: `{"message":"no profiles"}`,
name: "invalid test with empty profile",
service: Service{Name: "serviceNotExist", Address: "http://172.0.0.2:7777"},
param: ProfileParam{Force: true},
expectedErr: true,
expected: "no profiles",
},
{
name: "valid test with coverfile flag provied",
name: "valid test with coverfile flag provide",
service: Service{Name: "serviceOK", Address: profileSuccessMockSvr.URL},
param: ProfileParam{CoverFilePatterns: []string{"b.go$"}},
expected: "b/b.go",

View File

@ -173,7 +173,7 @@ func profile(c *gin.Context) {
}
if len(mergedProfiles) == 0 {
c.JSON(http.StatusOK, gin.H{"message": "no profiles"})
c.JSON(http.StatusExpectationFailed, gin.H{"error": "no profiles"})
return
}

View File

@ -94,6 +94,40 @@ setup() {
[[ "$output" == *"b.go"* ]] # contains b.go file
[[ "$output" != *"main.go"* ]] # not contains main.go file
wait $profile_pid
kill -9 $SAMPLE_PID
}
@test "test goc profile with service flag" {
./simple-project 3>&- &
SAMPLE_PID=$!
sleep 2
wait_profile_backend "profile4" &
profile_pid=$!
run gocc profile --center=http://127.0.0.1:60001 --service="simple-project" --debug --debugcisyncfile ci-sync.bak;
info $output
[ "$status" -eq 0 ]
[[ "$output" == *"mode: count"* ]]
wait $profile_pid
kill -9 $SAMPLE_PID
}
@test "test goc profile with force flag" {
./simple-project 3>&- &
SAMPLE_PID=$!
sleep 2
wait_profile_backend "profile5" &
profile_pid=$!
run gocc profile --center=http://127.0.0.1:60001 --service="simple-project,unknown" --force --debug --debugcisyncfile ci-sync.bak;
info $output
[ "$status" -eq 0 ]
[[ "$output" == *"mode: count"* ]]
wait $profile_pid
kill -9 $SAMPLE_PID
}

View File

@ -41,7 +41,9 @@ teardown_file() {
[ "$status" -eq 0 ]
# connect to covered goc
run goc profile --center=http://127.0.0.1:60001
[ "$status" -eq 0 ]
# no profiles
[ "$status" -eq 1 ]
[[ "$output" == *"no profiles"* ]]
}
@test "register a covered service" {
@ -54,5 +56,5 @@ teardown_file() {
sleep 1
# connect to covered goc
run goc profile --center=http://127.0.0.1:60001
[ "$status" -eq 0 ]
[ "$status" -eq 0 ]
}