Skip to content

Commit

Permalink
test(gnokms): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi committed Feb 25, 2025
1 parent 4209cff commit 6875723
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
8 changes: 4 additions & 4 deletions contribs/gnokms/internal/auth/auth_authorized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestAuthorizedAdd(t *testing.T) {
authorizedKey := "invalid"

// Run exec authorized key argument.
err := execAuthAuthorizedAdd(flags, []string{authorizedKey}, commands.NewDefaultIO())
err := execAuthAuthorizedAdd(flags, []string{authorizedKey}, commands.NewTestIO())
require.Error(t, err)
})

Expand All @@ -110,7 +110,7 @@ func TestAuthorizedAdd(t *testing.T) {
authorizedKey := ed25519.GenPrivKey().PubKey().String()

// Run exec authorized key argument.
err := execAuthAuthorizedAdd(flags, []string{authorizedKey}, commands.NewDefaultIO())
err := execAuthAuthorizedAdd(flags, []string{authorizedKey}, commands.NewTestIO())
require.Error(t, err)

// Turn it back to read-write for cleanup.
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestAuthorizedRemove(t *testing.T) {
authorizedKey := "invalid"

// Run exec authorized key argument.
err := execAuthAuthorizedRemove(flags, []string{authorizedKey}, commands.NewDefaultIO())
err := execAuthAuthorizedRemove(flags, []string{authorizedKey}, commands.NewTestIO())
require.Error(t, err)
})

Expand All @@ -223,7 +223,7 @@ func TestAuthorizedRemove(t *testing.T) {
authorizedKey := ed25519.GenPrivKey().PubKey().String()

// Run exec authorized key argument.
err := execAuthAuthorizedRemove(flags, []string{authorizedKey}, commands.NewDefaultIO())
err := execAuthAuthorizedRemove(flags, []string{authorizedKey}, commands.NewTestIO())
require.Error(t, err)

// Turn it back to read-write for cleanup.
Expand Down
2 changes: 1 addition & 1 deletion contribs/gnokms/internal/auth/auth_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestGenerate(t *testing.T) {
// Run exec with overwrite flag.
cmdErr = execAuthGenerate(
&authGenerateFlags{auth: flags, overwrite: true},
commands.NewDefaultIO(),
commands.NewTestIO(),
)
require.NoError(t, cmdErr)
})
Expand Down
5 changes: 3 additions & 2 deletions contribs/gnokms/internal/common/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func TestDefaultAuthKeysFile(t *testing.T) {

// Should fallback to the current directory.
wd, err := os.Getwd()
require.NoError(t, err)
require.Contains(t, defaultAuthKeysFile(), wd)
if err != nil {
require.Contains(t, defaultAuthKeysFile(), wd)
}
})

t.Run("no user directory and working dir", func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions contribs/gnokms/internal/common/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/gnolang/gno/tm2/pkg/log"
osm "github.com/gnolang/gno/tm2/pkg/os"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
)

func getFreePort(t *testing.T) int {
Expand Down Expand Up @@ -203,6 +204,7 @@ func TestRunSignerServer(t *testing.T) {

serverFlags := &ServerFlags{
ListenAddresses: getTCPAddress(t),
LogLevel: zapcore.ErrorLevel.String(),
AuthFlags: AuthFlags{
AuthKeysFile: filePath,
},
Expand All @@ -220,6 +222,7 @@ func TestRunSignerServer(t *testing.T) {

serverFlags := &ServerFlags{
ListenAddresses: getTCPAddress(t),
LogLevel: zapcore.ErrorLevel.String(),
}

// Listen on the address to make it unavailable.
Expand All @@ -238,6 +241,7 @@ func TestRunSignerServer(t *testing.T) {

serverFlags := &ServerFlags{
ListenAddresses: getTCPAddress(t),
LogLevel: zapcore.ErrorLevel.String(),
}

require.ErrorIs(t, RunSignerServer(
Expand All @@ -254,6 +258,7 @@ func TestRunSignerServer(t *testing.T) {

serverFlags := &ServerFlags{
ListenAddresses: getTCPAddress(t),
LogLevel: zapcore.ErrorLevel.String(),
}

// Simulate a SIGINT signal after 30 milliseconds.
Expand Down
8 changes: 4 additions & 4 deletions contribs/gnokms/internal/gnokey/gnokey_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestNewGnokeySigner(t *testing.T) {
defer keybase.CloseDB()

// Create a stdin with the password.
io := commands.NewDefaultIO()
io := commands.NewTestIO()
io.SetIn(strings.NewReader(fmt.Sprintf("%s\n%s\n", "invalid", keyPassword)))

signer, err := newGnokeySigner(
Expand All @@ -79,7 +79,7 @@ func TestNewGnokeySigner(t *testing.T) {
defer keybase.CloseDB()

// Create a stdin with the password.
io := commands.NewDefaultIO()
io := commands.NewTestIO()
io.SetIn(strings.NewReader(""))

signer, err := newGnokeySigner(
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestNewGnokeySigner(t *testing.T) {
require.NoError(t, err)

// Create a stdin with the password.
io := commands.NewDefaultIO()
io := commands.NewTestIO()
io.SetIn(strings.NewReader(""))

signer, err := newGnokeySigner(
Expand All @@ -130,7 +130,7 @@ func TestNewGnokeySigner(t *testing.T) {
defer keybase.CloseDB()

// Create a stdin with the password.
io := commands.NewDefaultIO()
io := commands.NewTestIO()
io.SetIn(strings.NewReader(fmt.Sprintf("%s\n", keyPassword)))

signer, err := newGnokeySigner(
Expand Down
6 changes: 5 additions & 1 deletion contribs/gnokms/internal/gnokey/gnokey_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gnokey

import (
"bytes"
"context"
"fmt"
"strings"
Expand All @@ -18,6 +19,7 @@ func TestNewGnokeyCmd(t *testing.T) {

cmd := NewGnokeyCmd(commands.NewTestIO())
require.NotNil(t, cmd)
cmd.SetOutput(commands.WriteNopCloser(new(bytes.Buffer)))

require.Error(t, cmd.ParseAndRun(context.Background(), []string{}))
})
Expand All @@ -39,7 +41,7 @@ func TestNewGnokeyCmd(t *testing.T) {
defer keybase.CloseDB()

// Create a stdin with the password.
io := commands.NewDefaultIO()
io := commands.NewTestIO()
io.SetIn(strings.NewReader(fmt.Sprintf("%s\n", keyPassword)))

cmd := NewGnokeyCmd(io)
Expand All @@ -48,6 +50,8 @@ func TestNewGnokeyCmd(t *testing.T) {
cmd.ParseAndRun(
context.Background(),
[]string{
"--log-level",
"error",
"--listeners",
"wrong_address",
"--home",
Expand Down

0 comments on commit 6875723

Please sign in to comment.