-
-
Notifications
You must be signed in to change notification settings - Fork 171
Open
Labels
enhancement 🌟New feature or requestNew feature or request
Description
What would you like to be added
Currently, Yorkie coverage is 38.31%. Some lines such as Client.Attach
, remain uncovered even though the tests execute Client.Attach
multiple times. But it seems some functionality is missing in testscript.
Why is this needed
Test enhancement can assure backward compatibility, no performance regression in case of new feature development or refactoring.
Good to add
- Add RPC test related to schema API (
CreateSchema
,GetSchema
, ...) (link) - Add test scenario calls cluster API (link)
- Add test cases which expects error
- ...
How to measure coverage enhancement in local
- Run
go test -tags integration -race -coverprofile=coverage_main.out -covermode=atomic ./...
in latest yorkie change - Add test - I newly added AdminRPC CreateSchema test with below.
./server/rpc/testcases/testcases.go
func RunAdminCreateSchemaTest(
t *testing.T,
testClient v1connect.YorkieServiceClient,
testAdminClient v1connect.AdminServiceClient,
testAdminAuthInterceptor *admin.AuthInterceptor,
) {
resp, err := testAdminClient.LogIn(
context.Background(),
connect.NewRequest(&api.LogInRequest{
Username: helper.AdminUser,
Password: helper.AdminPassword,
},
))
assert.NoError(t, err)
testAdminAuthInterceptor.SetToken(resp.Msg.Token)
_, err = testClient.ActivateClient(
context.Background(),
connect.NewRequest(&api.ActivateClientRequest{ClientKey: t.Name()}))
assert.NoError(t, err)
schemaRule1 := []types.Rule{
{
Path: "$.title",
Type: "string",
},
}
rule1 := converter.ToRules(schemaRule1)
_, err = testAdminClient.CreateSchema(
context.Background(),
connect.NewRequest(&api.CreateSchemaRequest{
ProjectName: defaultProjectName,
SchemaName: "test-schema",
SchemaVersion: 1,
SchemaBody: "type Document = {title: string;};",
Rules: rule1,
},
))
assert.NoError(t, err)
}
./server/rpc/server_test.go
t.Run("admin create schema test", func(t *testing.T) {
testcases.RunAdminCreateSchemaTest(t, testClient, testAdminClient, testAdminAuthInterceptor)
})
- Run
go test -tags integration -race -coverprofile=coverage_add.out -covermode=atomic ./…
- Add
compare_coverage.sh
in repository
#!/bin/bash
set -e
BASE=$1
HEAD=$2
if [ ! -f "$BASE" ]; then
echo "Base file '$BASE' not found."
exit 1
fi
if [ ! -f "$HEAD" ]; then
echo "Head file '$HEAD' not found."
exit 1
fi
sort "$BASE" > base.sorted
sort "$HEAD" > head.sorted
echo "------- Covered in BASE but not in HEAD -------"
join base.sorted head.sorted | awk '$3 >= 1 && $5 == 0 { print $1, $3 " -> " $5 }'
echo "------- Covered in HEAD but not in BASE -------"
join base.sorted head.sorted | awk '$3 == 0 && $5 >= 1 { print $1, $3 " -> " $5 }'
rm base.sorted head.sorted
chmod 777 compare_coverage.sh
./compare_coverage.sh coverage_main.out coverage_add.out
We can see 18 lines are additionally covers.
------- Covered in BASE but not in HEAD -------
------- Covered in HEAD but not in BASE -------
[[github.com/yorkie-team/yorkie/server/rpc/admin_server.go:648.56,650.42](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:648.56,650.42)](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:648.56,650.42) 0 -> 1
[[github.com/yorkie-team/yorkie/server/rpc/admin_server.go:654.2,655.16](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:654.2,655.16)](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:654.2,655.16) 0 -> 1
[[github.com/yorkie-team/yorkie/server/rpc/admin_server.go:659.2,668.16](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:659.2,668.16)](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:659.2,668.16) 0 -> 1
[[github.com/yorkie-team/yorkie/server/rpc/admin_server.go:672.2,674.9](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:672.2,674.9)](http://github.com/yorkie-team/yorkie/server/rpc/admin_server.go:672.2,674.9) 0 -> 1
kokodak, hackerwins, youngDaLee and sigmaithkokodak, hackerwins, youngDaLee and sigmaith
Metadata
Metadata
Assignees
Labels
enhancement 🌟New feature or requestNew feature or request
Type
Projects
Status
Backlog