Add test fixture

This commit is contained in:
Lunny Xiao
2025-08-11 19:37:09 -07:00
parent 93033237dd
commit 24053ce2d2
2 changed files with 50 additions and 2 deletions

View File

@ -6,6 +6,10 @@ on:
jobs:
check-and-test:
runs-on: ubuntu-latest
env:
GITEA_TEA_TEST_URL: "http://gitea:3000"
GITEA_TEA_TEST_USERNAME: "test01"
GITEA_TEA_TEST_PASSWORD: "test01"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
@ -24,3 +28,27 @@ jobs:
run: |
make test
make unit-test-coverage
services:
gitea:
image: docker.gitea.com/gitea:1.24.4
cmd:
- bash
- -c
- >-
mkdir -p /tmp/conf/
&& mkdir -p /tmp/data/
&& echo "I_AM_BEING_UNSAFE_RUNNING_AS_ROOT = true" > /tmp/conf/app.ini
&& echo "[security]" >> /tmp/conf/app.ini
&& echo "INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4" >> /tmp/conf/app.ini
&& echo "INSTALL_LOCK = true" >> /tmp/conf/app.ini
&& echo "SECRET_KEY = 2crAW4UANgvLipDS6U5obRcFosjSJHQANll6MNfX7P0G3se3fKcCwwK3szPyGcbo" >> /tmp/conf/app.ini
&& echo "PASSWORD_COMPLEXITY = off" >> /tmp/conf/app.ini
&& echo "[database]" >> /tmp/conf/app.ini
&& echo "DB_TYPE = sqlite3" >> /tmp/conf/app.ini
&& echo "[repository]" >> /tmp/conf/app.ini
&& echo "ROOT = /tmp/data/" >> /tmp/conf/app.ini
&& echo "[server]" >> /tmp/conf/app.ini
&& echo "ROOT_URL = http://gitea:3000" >> /tmp/conf/app.ini
&& gitea migrate -c /tmp/conf/app.ini
&& gitea admin user create --username=test01 --password=test01 --email=test01@gitea.io --admin=true --must-change-password=false --access-token -c /tmp/conf/app.ini
&& gitea web -c /tmp/conf/app.ini

View File

@ -6,15 +6,22 @@ package repos
import (
"context"
"fmt"
"os"
"testing"
"time"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/login"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v3"
)
func TestCreateRepoObjectFormat(t *testing.T) {
giteaURL := os.Getenv("GITEA_TEA_TEST_URL")
if giteaURL == "" {
t.Skip("GITEA_TEA_TEST_URL is not set, skipping test")
}
timestamp := time.Now().Unix()
tests := []struct {
name string
@ -49,13 +56,26 @@ func TestCreateRepoObjectFormat(t *testing.T) {
},
}
loginAddCmd := &cli.Command{
Name: "add",
Commands: []*cli.Command{
&login.CmdLoginAdd,
},
}
giteaUserName := os.Getenv("GITEA_TEA_TEST_USERNAME")
giteaUserPasword := os.Getenv("GITEA_TEA_TEST_PASSWORD")
args := []string{"add", "--name", "test-login", "--url", giteaURL, "--user", giteaUserName, "--password", giteaUserPasword}
err := loginAddCmd.Run(context.Background(), args)
assert.NoError(t, err)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reposCmd := &cli.Command{
Name: "repos",
Aliases: []string{"repo"},
Name: "repos",
Commands: []*cli.Command{&CmdRepoCreate},
}
tt.args = append(tt.args, "--login", "test-login")
args := append([]string{"repos", "create"}, tt.args...)
err := reposCmd.Run(context.Background(), args)