tests: add functionnal tests (e2e if you will)
This commit is contained in:
parent
f3cc8bdb10
commit
9174e537b6
4 changed files with 414 additions and 1 deletions
208
tests/functional/functional_test.go
Normal file
208
tests/functional/functional_test.go
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
// +build functional
|
||||
|
||||
package functional
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
// TestAPIConnection verifies we can connect to the Codeberg API with the test account
|
||||
func TestAPIConnection(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
env.VerifyAPIConnection()
|
||||
}
|
||||
|
||||
// TestListRepositories verifies we can list repositories
|
||||
func TestListRepositories(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
repos, _, err := env.Client.ListUserRepos(env.Owner, gitea.ListReposOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to list repositories: %v", err)
|
||||
}
|
||||
|
||||
if len(repos) == 0 {
|
||||
t.Fatalf("expected at least one repository, got none")
|
||||
}
|
||||
|
||||
t.Logf("Found %d repositories", len(repos))
|
||||
|
||||
// Verify we can find our test repo
|
||||
found := false
|
||||
for _, repo := range repos {
|
||||
if repo.Name == env.RepoName {
|
||||
found = true
|
||||
t.Logf("Found test repository: %s", repo.FullName)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatalf("test repository %s not found in user's repositories", env.RepoName)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetRepository verifies we can get repository details
|
||||
func TestGetRepository(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
repo, _, err := env.Client.GetRepo(env.Owner, env.RepoName)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get repository: %v", err)
|
||||
}
|
||||
|
||||
if repo.Name != env.RepoName {
|
||||
t.Fatalf("expected repo name %s, got %s", env.RepoName, repo.Name)
|
||||
}
|
||||
|
||||
if repo.Owner.UserName != env.Owner {
|
||||
t.Fatalf("expected owner %s, got %s", env.Owner, repo.Owner.UserName)
|
||||
}
|
||||
|
||||
t.Logf("Repository: %s (%s)", repo.FullName, repo.Description)
|
||||
}
|
||||
|
||||
// TestCreateAndListIssues verifies we can create and list issues
|
||||
func TestCreateAndListIssues(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Create a test issue
|
||||
issueNum := env.CreateTestIssue(
|
||||
"[FGJ E2E Test] Test Issue",
|
||||
"This is a functional test issue for fgj",
|
||||
)
|
||||
|
||||
defer env.CleanupIssue(issueNum)
|
||||
|
||||
// List issues
|
||||
issues, _, err := env.Client.ListRepoIssues(env.Owner, env.RepoName, gitea.ListIssueOption{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to list issues: %v", err)
|
||||
}
|
||||
|
||||
// Verify our created issue is in the list
|
||||
found := false
|
||||
for _, issue := range issues {
|
||||
if issue.Index == issueNum {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatalf("created issue #%d not found in issue list", issueNum)
|
||||
}
|
||||
|
||||
t.Logf("Successfully created and listed issue #%d", issueNum)
|
||||
}
|
||||
|
||||
// TestGetIssue verifies we can get issue details
|
||||
func TestGetIssue(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Create a test issue
|
||||
issueNum := env.CreateTestIssue(
|
||||
"[FGJ E2E Test] Get Issue Test",
|
||||
"Testing get issue functionality",
|
||||
)
|
||||
|
||||
defer env.CleanupIssue(issueNum)
|
||||
|
||||
// Get the issue
|
||||
issue, _, err := env.Client.GetIssue(env.Owner, env.RepoName, issueNum)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get issue: %v", err)
|
||||
}
|
||||
|
||||
if issue.Index != issueNum {
|
||||
t.Fatalf("expected issue number %d, got %d", issueNum, issue.Index)
|
||||
}
|
||||
|
||||
if issue.Title != "[FGJ E2E Test] Get Issue Test" {
|
||||
t.Fatalf("issue title mismatch")
|
||||
}
|
||||
|
||||
t.Logf("Retrieved issue #%d: %s", issueNum, issue.Title)
|
||||
}
|
||||
|
||||
// TestCommentOnIssue verifies we can comment on issues
|
||||
func TestCommentOnIssue(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Create a test issue
|
||||
issueNum := env.CreateTestIssue(
|
||||
"[FGJ E2E Test] Comment Test",
|
||||
"Testing comment functionality",
|
||||
)
|
||||
|
||||
defer env.CleanupIssue(issueNum)
|
||||
|
||||
// Add a comment
|
||||
comment, _, err := env.Client.CreateIssueComment(
|
||||
env.Owner,
|
||||
env.RepoName,
|
||||
issueNum,
|
||||
gitea.CreateIssueCommentOption{
|
||||
Body: "This is an automated test comment from fgj functional tests",
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create issue comment: %v", err)
|
||||
}
|
||||
|
||||
if comment.Body != "This is an automated test comment from fgj functional tests" {
|
||||
t.Fatalf("comment body mismatch")
|
||||
}
|
||||
|
||||
t.Logf("Successfully added comment to issue #%d", issueNum)
|
||||
}
|
||||
|
||||
// TestGetRepositoryWithCollaborators verifies we can get repo and check collaborators
|
||||
func TestGetRepositoryWithCollaborators(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Get repository with full details
|
||||
repo, _, err := env.Client.GetRepo(env.Owner, env.RepoName)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get repository: %v", err)
|
||||
}
|
||||
|
||||
// Verify basic repo properties
|
||||
if repo.FullName != env.Owner+"/"+env.RepoName {
|
||||
t.Fatalf("expected repo full name %s/%s, got %s", env.Owner, env.RepoName, repo.FullName)
|
||||
}
|
||||
|
||||
t.Logf("Repository %s has %d watchers, %d stars, %d forks",
|
||||
repo.FullName, repo.Watchers, repo.Stars, repo.Forks)
|
||||
}
|
||||
|
||||
// TestAPIErrorHandling verifies proper error handling for invalid requests
|
||||
func TestAPIErrorHandling(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
// Try to get a non-existent issue
|
||||
_, _, err := env.Client.GetIssue(env.Owner, env.RepoName, 999999)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error for non-existent issue, got none")
|
||||
}
|
||||
|
||||
t.Logf("Properly handled error: %v", err)
|
||||
}
|
||||
|
||||
// TestRepositoryExists verifies the test repository exists and is accessible
|
||||
func TestRepositoryExists(t *testing.T) {
|
||||
env := NewTestEnv(t)
|
||||
|
||||
repo, _, err := env.Client.GetRepo(env.Owner, env.RepoName)
|
||||
if err != nil {
|
||||
t.Fatalf("test repository does not exist or is not accessible: %v", err)
|
||||
}
|
||||
|
||||
if repo.Private {
|
||||
t.Logf("Test repository is private: %s", repo.FullName)
|
||||
} else {
|
||||
t.Logf("Test repository is public: %s", repo.FullName)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue