package cli_test import ( "testing" "git.eeqj.de/sneak/secret/internal/cli" "git.eeqj.de/sneak/secret/internal/vault" "github.com/spf13/cobra" ) // TestMissingSecretOrVaultErrors checks that a command that finds no such // secret or vault returns the vault package's error for it, as `secret get` // does, and leaves the vaults unchanged. "default" is the current vault, and // both vaults hold the secret "x". func TestMissingSecretOrVaultErrors(t *testing.T) { t.Parallel() before := snapshotStateDir(t, newTwoVaultFs(t)) tests := []struct { command string want error run func(c *cli.Instance) error }{ { "rm --force nosuch", vault.ErrSecretNotFound, func(c *cli.Instance) error { return c.RemoveSecret(&cobra.Command{}, "nosuch", true) }, }, { "version rm --force nosuch", vault.ErrSecretNotFound, func(c *cli.Instance) error { return c.RemoveVersion(&cobra.Command{}, "nosuch", "20260101.001", true) }, }, { "mv --force work:nosuch default", vault.ErrSecretNotFound, func(c *cli.Instance) error { return c.MoveSecret(&cobra.Command{}, "work:nosuch", "default", true) }, }, { "decrypt nosuch", vault.ErrSecretNotFound, func(c *cli.Instance) error { return c.Decrypt("nosuch", "", "") }, }, { "vault rm --force nosuch", vault.ErrVaultNotFound, func(c *cli.Instance) error { return c.RemoveVault(&cobra.Command{}, "nosuch", true) }, }, } for _, tt := range tests { t.Run(tt.command, func(t *testing.T) { t.Parallel() requireRejectedAndUnchanged(t, before, tt.want, tt.run) }) } }