Skip to content

Commit

Permalink
run integration tests in GH action
Browse files Browse the repository at this point in the history
  • Loading branch information
qrort committed Sep 11, 2024
1 parent 44058b2 commit bf0d6be
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 9 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/go-test.yml → .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [opened, synchronize, reopened]

jobs:
test:
unittest:
runs-on: ubuntu-latest
outputs:
job-summary: ${{ steps.job-summary.outputs.job-summary }}
Expand Down Expand Up @@ -50,9 +50,9 @@ jobs:
with:
create-pdf: false

comment-pr:
comment-unittest:
runs-on: ubuntu-latest
needs: test
needs: unittest
steps:
- name: Comment on PR
uses: peter-evans/create-or-update-comment@v2
Expand All @@ -61,3 +61,20 @@ jobs:
repository: ${{ github.repository }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ needs.test.outputs.job-summary }}

integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: supply with s3 access keys
run: |
echo "ydbcp" > access_key
echo "password" > secret_key
- name: docker compose up
run: |
docker compose up --build -d
- name: run integration tests
run: docker exec local-ydbcp sh -c './integration'
- name: docker compose down
run: |
docker compose down
136 changes: 136 additions & 0 deletions cmd/integration/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package main

import (
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"log"
"time"
"ydbcp/internal/types"
pb "ydbcp/pkg/proto/ydbcp/v1alpha1"
)

const (
containerID = "abcde"
databaseName = "/local"
ydbcpEndpoint = "localhost:50051"
databaseEndpoint = "grpcs://local-ydb:2135"
)

func main() {
var opts []grpc.DialOption
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(ydbcpEndpoint, opts...)
if err != nil {
log.Panicln("failed to dial")
}
defer func(conn *grpc.ClientConn) {
err := conn.Close()
if err != nil {
log.Panicln("failed to close connection")
}
}(conn)
client := pb.NewBackupServiceClient(conn)
backups, err := client.ListBackups(
context.Background(), &pb.ListBackupsRequest{
ContainerId: containerID,
DatabaseNameMask: "%",
},
)
if err != nil {
log.Panicf("failed to list backups: %v", err)
}
if len(backups.Backups) > 0 {
log.Panicf("got backup from empty YDBCP: %s", backups.Backups[0].String())
}
backupOperation, err := client.MakeBackup(
context.Background(), &pb.MakeBackupRequest{
ContainerId: containerID,
DatabaseName: databaseName,
DatabaseEndpoint: databaseEndpoint,
SourcePaths: nil,
SourcePathsToExclude: nil,
},
)
if err != nil {
log.Panicf("failed to make backup: %v", err)
}
backups, err = client.ListBackups(
context.Background(), &pb.ListBackupsRequest{
ContainerId: containerID,
DatabaseNameMask: "%",
},
)
if err != nil {
log.Panicf("failed to list backups: %v", err)
}
if len(backups.Backups) != 1 {
log.Panicf("Did not list freshly made backup")
}
backupPb := backups.Backups[0]
if backupPb.Id != backupOperation.BackupId {
log.Panicf(
"backupOperation backupID %s does not match listed backup id %s", backupOperation.BackupId, backupPb.Id,
)
}
done := false
for range 30 {
backup, err := client.GetBackup(
context.Background(),
&pb.GetBackupRequest{Id: backupOperation.BackupId},
)
if err != nil {
log.Panicf("failed to get backup: %v", err)
}
if backup.GetStatus().String() == types.BackupStateAvailable {
done = true
break
}
time.Sleep(time.Second)
}
if !done {
log.Panicln("failed to complete a backup in 30 seconds")
}
scheduleClient := pb.NewBackupScheduleServiceClient(conn)
schedules, err := scheduleClient.ListBackupSchedules(
context.Background(), &pb.ListBackupSchedulesRequest{
ContainerId: containerID,
DatabaseNameMask: "%",
},
)
if err != nil {
log.Panicf("failed to list backup schedules: %v", err)
}
if len(schedules.Schedules) > 0 {
log.Panicf("got backup schedule, but none created: %s", schedules.Schedules[0].String())
}
schedule, err := scheduleClient.CreateBackupSchedule(
context.Background(), &pb.CreateBackupScheduleRequest{
ContainerId: containerID,
DatabaseName: databaseName,
Endpoint: databaseEndpoint,
ScheduleName: "schedule",
ScheduleSettings: &pb.BackupScheduleSettings{
SchedulePattern: &pb.BackupSchedulePattern{Crontab: "* * * * * *"},
},
},
)
if err != nil {
log.Panicf("failed to create backup schedule: %v", err)
}
schedules, err = scheduleClient.ListBackupSchedules(
context.Background(), &pb.ListBackupSchedulesRequest{
ContainerId: containerID,
DatabaseNameMask: "%",
},
)
if err != nil {
log.Panicf("failed to list backup schedules: %v", err)
}
if len(schedules.Schedules) != 1 {
log.Panicln("did not list created schedule")
}
if schedules.Schedules[0].Id != schedule.Id {
log.Panicf("schedule and listed schedule ids does not match: %s, %s", schedules.Schedules[0].Id, schedule.Id)
}
}
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ services:
S3_ENDPOINT: http://${S3_NAME}:9000
S3_REGION: ${S3_REGION}
S3_BUCKET: ${S3_BUCKET}
#S3_ACCESS_KEY: ${S3_ACCESS_KEY}
#S3_SECRET_KEY: ${S3_SECRET_KEY}
S3_ACCESS_KEY: ${S3_ACCESS_KEY}
S3_SECRET_KEY: ${S3_SECRET_KEY}
YDB_NAME: ${YDB_NAME}

depends_on:
Expand Down
5 changes: 4 additions & 1 deletion dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ RUN go mod download
# Build the Go app
RUN go build -o . ./cmd/ydbcp/main.go

# Build integration test app
RUN go build -o ./integration ./cmd/integration/main.go

# Command to run the executable
CMD ["./main", "--config=local_config.yaml"]
CMD ["./main", "--config=local_config.yaml"]
6 changes: 3 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi

if [[ "docker" == "$2" ]]; then
YDBCP_ENDPOINT="localhost:50051"
YDB_ENDPOINT="grpcs://local-ydb:2136"
YDB_ENDPOINT="grpcs://local-ydb:2135"
YDB_DBNAME="/local"
fi

Expand Down Expand Up @@ -59,10 +59,10 @@ if [[ "ListOperations" == "$1" ]]; then
fi
if [[ "MakeBackup" == "$1" ]]; then
doneflag=1
$GRPCURL "${ARGS[@]}" -d '{"database_name": "'"${YDB_DBNAME}"'", "database_endpoint": "'"${YDB_ENDPOINT}"'", "source_paths": ["'"${YDB_DBNAME}"'"], "containerId": "'"$CONTAINER_ID"'"}' ${YDBCP_ENDPOINT} ydbcp.v1alpha1.BackupService.MakeBackup
$GRPCURL "${ARGS[@]}" -d '{"database_name": "'"${YDB_DBNAME}"'", "database_endpoint": "'"${YDB_ENDPOINT}"'", "containerId": "'"$CONTAINER_ID"'"}' ${YDBCP_ENDPOINT} ydbcp.v1alpha1.BackupService.MakeBackup
fi
if [[ "CreateBackupSchedule" == "$1" ]]; then
$GRPCURL "${ARGS[@]}" -d '{"database_name": "'"${YDB_DBNAME}"'", "endpoint": "'"${YDB_ENDPOINT}"'", "source_paths": ["'"${YDB_DBNAME}"'"], "containerId": "'"$CONTAINER_ID"'", "schedule_settings": {"schedule_pattern": {"crontab": "* * * * * *"}}}' ${YDBCP_ENDPOINT} ydbcp.v1alpha1.BackupScheduleService.CreateBackupSchedule
$GRPCURL "${ARGS[@]}" -d '{"database_name": "'"${YDB_DBNAME}"'", "endpoint": "'"${YDB_ENDPOINT}"'", "containerId": "'"$CONTAINER_ID"'", "schedule_settings": {"schedule_pattern": {"crontab": "* * * * * *"}}}' ${YDBCP_ENDPOINT} ydbcp.v1alpha1.BackupScheduleService.CreateBackupSchedule
doneflag=1
fi

Expand Down

0 comments on commit bf0d6be

Please sign in to comment.