Skip to content

Commit

Permalink
refactor: improve ssh key gen on tests
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Oct 6, 2023
1 parent f9cc204 commit 7efeeb3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions internal/client/git_test.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions internal/pipe/aur/aur_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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{
Expand Down
3 changes: 1 addition & 2 deletions internal/pipe/brew/brew_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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, ""),
},
}
},
Expand Down
3 changes: 1 addition & 2 deletions internal/pipe/krew/krew_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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, ""),
},
}
},
Expand Down
3 changes: 1 addition & 2 deletions internal/pipe/scoop/scoop_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion internal/testlib/git.go
Expand Up @@ -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(
Expand Down

0 comments on commit 7efeeb3

Please sign in to comment.