From 0f6cb392d66a69da96ccd37bb987b91a48899b6e2d7beaacd4a41e92dcbd6241 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Wed, 30 Oct 2024 16:55:51 +0100 Subject: [PATCH] wip tests --- workflow-direct/main_test.go | 4 ++- workflow-pr/main_test.go | 60 +++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/workflow-direct/main_test.go b/workflow-direct/main_test.go index 80831b7..366a1bb 100644 --- a/workflow-direct/main_test.go +++ b/workflow-direct/main_test.go @@ -1,4 +1,6 @@ package main // TODO, like documentation :-) - +func test() +{ +} diff --git a/workflow-pr/main_test.go b/workflow-pr/main_test.go index 0a9f7f2..36ad4b5 100644 --- a/workflow-pr/main_test.go +++ b/workflow-pr/main_test.go @@ -1,3 +1,61 @@ package main -// TODO +import ( + "testing" + + "src.opensuse.org/autogits/common" +) + +func TestProjectBranchName(t *testing.T) { + req := common.PullRequestWebhookEvent{ + Repository: &common.Repository{ + Name: "testingRepo", + }, + Pull_Request: &common.PullRequest{ + Number: 10, + }, + } + + branchName := prGitBranchNameForPR(&req) + if branchName != "PR_testingRepo#10" { + t.Error("Unexpected branch name:", branchName) + } +} + +func TestProjctGitSync(t *testing.T) { + req := common.PullRequestWebhookEvent{ + Action: "pull", + Number: 0, + } + + if err := processPrjGitPullRequestSync(&req); err != nil { + t.Error(err) + } +} + +func setupGitForTests(dir string) error { + return nil +} + +func TestPkgGitSync(t *testing.T) { + req := common.PullRequestWebhookEvent{ + Repository: &common.Repository{ + Name: "testRepo", + }, + } + + git := common.GitHandler{ + DebugLogger: true, + GitCommiter: "TestCommiter", + GitEmail: "test@testing", + GitPath: t.TempDir(), + } + + if err := setupGitForTests(git.GitPath); err != nil { + t.Fatal(err) + } + + if err := updateOrCreatePRBranch(&req, &git, "created commit", "testing"); err != nil { + t.Error(err) + } +}