Skip to content

Commit

Permalink
[bugfix] Fix writes to global config from tests
Browse files Browse the repository at this point in the history
Fixes gopasspw#2725

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz committed Dec 1, 2023
1 parent bf426e6 commit be5b76e
Show file tree
Hide file tree
Showing 107 changed files with 322 additions and 221 deletions.
2 changes: 1 addition & 1 deletion internal/action/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newMock(ctx context.Context, path string) (*Action, error) {
func TestAction(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithInteractive(ctx, false)

act, err := newMock(ctx, u.StoreDir(""))
Expand Down
3 changes: 2 additions & 1 deletion internal/action/aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
Expand All @@ -15,7 +16,7 @@ import (
func TestAliases(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)
act, err := newMock(ctx, u.StoreDir(""))
Expand Down
3 changes: 2 additions & 1 deletion internal/action/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/gopass/secrets"
Expand All @@ -17,7 +18,7 @@ import (
func TestAudit(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)
act, err := newMock(ctx, u.StoreDir(""))
Expand Down
13 changes: 7 additions & 6 deletions internal/action/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
Expand All @@ -19,7 +20,7 @@ import (
func TestBinary(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)

Expand All @@ -45,7 +46,7 @@ func TestBinaryCat(t *testing.T) {

u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)

Expand Down Expand Up @@ -100,7 +101,7 @@ func TestBinaryCat(t *testing.T) {
func TestBinaryCatSizes(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)

Expand Down Expand Up @@ -154,7 +155,7 @@ func TestBinaryCatSizes(t *testing.T) {
func TestBinaryCopy(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)

Expand Down Expand Up @@ -216,7 +217,7 @@ func TestBinaryCopy(t *testing.T) {
func TestBinarySum(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)

Expand Down Expand Up @@ -247,7 +248,7 @@ func TestBinarySum(t *testing.T) {
func TestBinaryGet(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithHidden(ctx, true)

Expand Down
8 changes: 4 additions & 4 deletions internal/action/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func aGitRepo(ctx context.Context, t *testing.T, u *gptest.Unit, name string) st
func TestClone(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithInteractive(ctx, false)
ctx = backend.WithStorageBackend(ctx, backend.GitFS)
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestCloneBackendIsStoredForMount(t *testing.T) {
stdout = os.Stdout
}()

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithInteractive(ctx, false)

Expand Down Expand Up @@ -125,7 +125,7 @@ func TestCloneGetGitConfig(t *testing.T) {
r2 := gptest.UnsetVars(termio.EmailVars...)
defer r2()

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithInteractive(ctx, false)

Expand Down Expand Up @@ -153,7 +153,7 @@ func TestCloneCheckDecryptionKeys(t *testing.T) {
stdout = os.Stdout
}()

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithInteractive(ctx, false)

Expand Down
3 changes: 2 additions & 1 deletion internal/action/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -40,7 +41,7 @@ func testCommand(t *testing.T, cmd *cli.Command) {
func TestCommands(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithInteractive(ctx, false)
act, err := newMock(ctx, u.StoreDir(""))
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion internal/action/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestComplete(t *testing.T) {
stdout = os.Stdout
}()

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithInteractive(ctx, false)
act, err := newMock(ctx, u.StoreDir(""))
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion internal/action/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
Expand All @@ -17,7 +18,7 @@ import (
func TestConfig(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithInteractive(ctx, false)
act, err := newMock(ctx, u.StoreDir(""))
require.NoError(t, err)
Expand Down
15 changes: 8 additions & 7 deletions internal/action/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/stretchr/testify/assert"
)

func TestWithClip(t *testing.T) {
ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())

if IsClip(ctx) {
t.Errorf("Should be false")
Expand All @@ -20,7 +21,7 @@ func TestWithClip(t *testing.T) {
}

func TestWithPasswordOnly(t *testing.T) {
ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())

if IsPasswordOnly(ctx) {
t.Errorf("Should be false")
Expand All @@ -32,14 +33,14 @@ func TestWithPasswordOnly(t *testing.T) {
}

func TestWithPrintQR(t *testing.T) {
ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())

assert.False(t, IsPrintQR(ctx))
assert.True(t, IsPrintQR(WithPrintQR(ctx, true)))
}

func TestWithRevision(t *testing.T) {
ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())

assert.Equal(t, "", GetRevision(ctx))
assert.Equal(t, "foo", GetRevision(WithRevision(ctx, "foo")))
Expand All @@ -48,21 +49,21 @@ func TestWithRevision(t *testing.T) {
}

func TestWithKey(t *testing.T) {
ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())

assert.Equal(t, "", GetKey(ctx))
assert.Equal(t, "foo", GetKey(WithKey(ctx, "foo")))
}

func TestWithOnlyClip(t *testing.T) {
ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())

assert.False(t, IsOnlyClip(ctx))
assert.True(t, IsOnlyClip(WithOnlyClip(ctx, true)))
}

func TestWithAlsoClip(t *testing.T) {
ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())

assert.False(t, IsAlsoClip(ctx))
assert.True(t, IsAlsoClip(WithAlsoClip(ctx, true)))
Expand Down
3 changes: 2 additions & 1 deletion internal/action/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/fatih/color"
"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/gopass/secrets"
Expand All @@ -17,7 +18,7 @@ import (
func TestConvert(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithTerminal(ctx, false)
ctx = ctxutil.WithInteractive(ctx, false)
Expand Down
5 changes: 3 additions & 2 deletions internal/action/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/fatih/color"
"github.com/gopasspw/gopass/internal/backend"
"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
Expand All @@ -18,7 +19,7 @@ import (
func TestCopy(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithInteractive(ctx, false)
ctx = ctxutil.WithAlwaysYes(ctx, true)

Expand Down Expand Up @@ -100,7 +101,7 @@ func TestCopyGpg(t *testing.T) {

u := gptest.NewGUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithInteractive(ctx, false)
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = backend.WithCryptoBackend(ctx, backend.GPGCLI)
Expand Down
3 changes: 2 additions & 1 deletion internal/action/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

aclip "github.com/atotto/clipboard"
"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
Expand All @@ -18,7 +19,7 @@ func TestCreate(t *testing.T) {

aclip.Unsupported = true

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)

act, err := newMock(ctx, u.StoreDir(""))
Expand Down
3 changes: 2 additions & 1 deletion internal/action/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/gopass/secrets"
Expand All @@ -16,7 +17,7 @@ import (
func TestDelete(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithInteractive(ctx, false)
act, err := newMock(ctx, u.StoreDir(""))
Expand Down
5 changes: 3 additions & 2 deletions internal/action/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
Expand All @@ -15,7 +16,7 @@ import (
func TestEdit(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithTerminal(ctx, false)
act, err := newMock(ctx, u.StoreDir(""))
Expand Down Expand Up @@ -45,7 +46,7 @@ func TestEdit(t *testing.T) {
func TestEditUpdate(t *testing.T) {
u := gptest.NewUnitTester(t)

ctx := context.Background()
ctx := config.NewNoWrites().WithConfig(context.Background())
ctx = ctxutil.WithAlwaysYes(ctx, true)
ctx = ctxutil.WithTerminal(ctx, false)
act, err := newMock(ctx, u.StoreDir(""))
Expand Down
Loading

0 comments on commit be5b76e

Please sign in to comment.