1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-17 01:42:37 +02:00

refactor: improve ssh key gen on tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2023-10-06 14:16:51 +00:00
parent f9cc204afc
commit 7efeeb37c1
6 changed files with 20 additions and 20 deletions

View File

@ -25,7 +25,7 @@ func TestGitClient(t *testing.T) {
})
repo := Repo{
GitURL: url,
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
Name: "test1",
}
cli := NewGitUploadClient(repo.Branch)
@ -60,7 +60,7 @@ func TestGitClient(t *testing.T) {
})
repo := Repo{
GitURL: url,
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
Name: "test1",
Branch: "new-branch",
}
@ -107,7 +107,7 @@ func TestGitClient(t *testing.T) {
})
repo := Repo{
GitURL: url,
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
}
cli := NewGitUploadClient(repo.Branch)
require.NoError(t, cli.CreateFile(
@ -151,7 +151,7 @@ func TestGitClient(t *testing.T) {
})
repo := Repo{
GitURL: "git@github.com:nope/nopenopenopenope",
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
}
cli := NewGitUploadClient(repo.Branch)
err := cli.CreateFile(
@ -171,7 +171,7 @@ func TestGitClient(t *testing.T) {
})
repo := Repo{
GitURL: testlib.GitMakeBareRepository(t),
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
GitSSHCommand: "{{.Foo}}",
}
cli := NewGitUploadClient(repo.Branch)
@ -239,7 +239,7 @@ func TestGitClient(t *testing.T) {
func TestKeyPath(t *testing.T) {
t.Run("with valid path", func(t *testing.T) {
path := testlib.MakeNewSSHKey(t, keygen.Ed25519, "")
path := testlib.MakeNewSSHKey(t, "")
result, err := keyPath(path)
require.NoError(t, err)
require.Equal(t, path, result)
@ -251,7 +251,7 @@ func TestKeyPath(t *testing.T) {
})
t.Run("with password protected key path", func(t *testing.T) {
path := testlib.MakeNewSSHKey(t, keygen.Ed25519, "pwd")
path := testlib.MakeNewSSHKey(t, "pwd")
bts, err := os.ReadFile(path)
require.NoError(t, err)
@ -263,7 +263,7 @@ func TestKeyPath(t *testing.T) {
t.Run("with key", func(t *testing.T) {
for _, algo := range []keygen.KeyType{keygen.Ed25519, keygen.RSA} {
t.Run(string(algo), func(t *testing.T) {
path := testlib.MakeNewSSHKey(t, algo, "")
path := testlib.MakeNewSSHKeyType(t, "", algo)
bts, err := os.ReadFile(path)
require.NoError(t, err)
@ -282,7 +282,7 @@ func TestKeyPath(t *testing.T) {
require.Equal(t, "", result)
})
t.Run("with invalid EOF", func(t *testing.T) {
path := testlib.MakeNewSSHKey(t, keygen.Ed25519, "")
path := testlib.MakeNewSSHKey(t, "")
bts, err := os.ReadFile(path)
require.NoError(t, err)

View File

@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"
"github.com/charmbracelet/keygen"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/git"
@ -245,7 +244,7 @@ func TestFullPipe(t *testing.T) {
} {
t.Run(name, func(t *testing.T) {
url := testlib.GitMakeBareRepository(t)
key := testlib.MakeNewSSHKey(t, keygen.Ed25519, "")
key := testlib.MakeNewSSHKey(t, "")
folder := t.TempDir()
ctx := testctx.NewWithCfg(
@ -352,7 +351,7 @@ func TestFullPipe(t *testing.T) {
func TestRunPipe(t *testing.T) {
url := testlib.GitMakeBareRepository(t)
key := testlib.MakeNewSSHKey(t, keygen.Ed25519, "")
key := testlib.MakeNewSSHKey(t, "")
folder := t.TempDir()
ctx := testctx.NewWithCfg(
@ -488,7 +487,7 @@ func TestRunPipeNoBuilds(t *testing.T) {
func TestRunPipeBinaryRelease(t *testing.T) {
url := testlib.GitMakeBareRepository(t)
key := testlib.MakeNewSSHKey(t, keygen.Ed25519, "")
key := testlib.MakeNewSSHKey(t, "")
folder := t.TempDir()
ctx := testctx.NewWithCfg(
config.Project{

View File

@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"
"github.com/charmbracelet/keygen"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/golden"
@ -186,7 +185,7 @@ func TestFullPipe(t *testing.T) {
Branch: "main",
Git: config.GitRepoRef{
URL: testlib.GitMakeBareRepository(t),
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
},
}
},

View File

@ -9,7 +9,6 @@ import (
"strings"
"testing"
"github.com/charmbracelet/keygen"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/golden"
@ -159,7 +158,7 @@ func TestFullPipe(t *testing.T) {
Branch: "main",
Git: config.GitRepoRef{
URL: testlib.GitMakeBareRepository(t),
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
},
}
},

View File

@ -5,7 +5,6 @@ import (
"path/filepath"
"testing"
"github.com/charmbracelet/keygen"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/golden"
@ -239,7 +238,7 @@ func Test_doRun(t *testing.T) {
Branch: "main",
Git: config.GitRepoRef{
URL: testlib.GitMakeBareRepository(t),
PrivateKey: testlib.MakeNewSSHKey(t, keygen.Ed25519, ""),
PrivateKey: testlib.MakeNewSSHKey(t, ""),
},
},
Folder: "scoops",

View File

@ -113,9 +113,13 @@ func GitMakeBareRepository(tb testing.TB) string {
return dir
}
func MakeNewSSHKey(tb testing.TB, algo keygen.KeyType, pass string) string {
func MakeNewSSHKey(tb testing.TB, pass string) string {
tb.Helper()
return MakeNewSSHKeyType(tb, pass, keygen.Ed25519)
}
func MakeNewSSHKeyType(tb testing.TB, pass string, algo keygen.KeyType) string {
tb.Helper()
dir := tb.TempDir()
filepath := filepath.Join(dir, "id_"+algo.String())
_, err := keygen.New(