// Copyright 2024 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package repos import ( "testing" "code.gitea.io/sdk/gitea" "github.com/stretchr/testify/assert" "github.com/urfave/cli/v2" ) func TestCreateRepoObjectFormat(t *testing.T) { tests := []struct { name string args []string wantOpts gitea.CreateRepoOption wantErr bool errContains string }{ { name: "create repo with sha1 object format", args: []string{"--name", "test-sha1", "--object-format", "sha1"}, wantOpts: gitea.CreateRepoOption{ Name: "test-sha1", ObjectFormatName: "sha1", }, wantErr: false, }, { name: "create repo with sha256 object format", args: []string{"--name", "test-sha256", "--object-format", "sha256"}, wantOpts: gitea.CreateRepoOption{ Name: "test-sha256", ObjectFormatName: "sha256", }, wantErr: false, }, { name: "create repo with invalid object format", args: []string{"--name", "test-invalid", "--object-format", "invalid"}, wantErr: true, errContains: "invalid object format", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { app := cli.NewApp() app.Commands = []*cli.Command{&CmdRepoCreate} args := append([]string{"tea", "repo", "create"}, tt.args...) err := app.Run(args) if tt.wantErr { assert.Error(t, err) if tt.errContains != "" { assert.Contains(t, err.Error(), tt.errContains) } return } assert.NoError(t, err) // Note: We can't directly test the CreateRepoOption since it's created inside runRepoCreate // In a real test environment, we would mock the client and verify the options passed to it }) } }