mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-10 07:26:33 -04:00
- Add deploy-tokens subcommand with list, create, delete - Create deploy token print helpers with token display (shown once only) - Add unit tests for all commands - Update SDK dependency to use fork with deploy token support Relates to gitea/go-sdk#846
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package deploytokens
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dev/sdk"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
func TestCreateCommandMetadata(t *testing.T) {
|
|
cmd := &CmdDeployTokensCreate
|
|
|
|
assert.Equal(t, "create", cmd.Name)
|
|
for _, want := range []string{"add", "c"} {
|
|
assert.Contains(t, cmd.Aliases, want)
|
|
}
|
|
assert.Equal(t, "Create a deploy token", cmd.Usage)
|
|
assert.Equal(t, "<token-title>", cmd.ArgsUsage)
|
|
assert.NotNil(t, cmd.Action)
|
|
}
|
|
|
|
func TestCreateCommandFlags(t *testing.T) {
|
|
cmd := &CmdDeployTokensCreate
|
|
|
|
have := make(map[string]bool, len(cmd.Flags))
|
|
for _, flag := range cmd.Flags {
|
|
have[flag.Names()[0]] = true
|
|
}
|
|
for _, name := range []string{"read-only", "read-write", "login", "repo", "remote", "output"} {
|
|
assert.True(t, have[name], "expected flag %q not found", name)
|
|
}
|
|
}
|
|
|
|
func TestCreateReadOnlyDefault(t *testing.T) {
|
|
for _, flag := range CmdDeployTokensCreate.Flags {
|
|
if bf, ok := flag.(*cli.BoolFlag); ok && bf.Name == "read-only" {
|
|
assert.True(t, bf.Value, "--read-only should default to true")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCreateTokenOptionConstruction(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
title string
|
|
readOnly bool
|
|
}{
|
|
{"read-only token", "ci", true},
|
|
{"read-write token", "deploy-bot", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
opt := gitea.CreateDeployKeyTokenOption{
|
|
Title: tt.title,
|
|
ReadOnly: tt.readOnly,
|
|
}
|
|
assert.Equal(t, tt.title, opt.Title)
|
|
assert.Equal(t, tt.readOnly, opt.ReadOnly)
|
|
})
|
|
}
|
|
}
|