Merge pull request #4087 from asaah262/fix/4083-decomposedfs-metadata-flags

fix(cli): pass --root and --node on to the decomposedfs metadata subcommands
This commit is contained in:
Sara Ahmadi authored and GitHub committed 2026-11-24 12:12:42 +01:00
commit aa83ea94c8
2 files changed
+66 -4

No files matched your search

+5 -4
View File
@@ -183,10 +183,11 @@ func metadataCmd(cfg *config.Config) *cobra.Command {
Short: `cli tools to inspect and manipulate node metadata`,
}
metaCmd.AddCommand(dumpCmd(cfg), getCmd(cfg), setCmd(cfg))
metaCmd.Flags().StringP("root", "r", "", "Path to the root directory of the decomposedfs")
_ = metaCmd.MarkFlagRequired("root")
metaCmd.Flags().StringP("node", "n", "", "Path to or ID of the node to inspect")
_ = metaCmd.MarkFlagRequired("node")
// persistent, so that the subcommands dump, get and set, which read them, have them
metaCmd.PersistentFlags().StringP("root", "r", "", "Path to the root directory of the decomposedfs")
_ = metaCmd.MarkPersistentFlagRequired("root")
metaCmd.PersistentFlags().StringP("node", "n", "", "Path to or ID of the node to inspect")
_ = metaCmd.MarkPersistentFlagRequired("node")
return metaCmd
}
@@ -1,6 +1,7 @@
package command
import (
"io"
"testing"
"github.com/opencloud-eu/reva/v3/pkg/storage/pkg/decomposedfs/metadata"
@@ -36,3 +37,63 @@ func TestGetBackend(t *testing.T) {
require.Nil(t, b)
})
}
// runMetadataCmd runs "opencloud decomposedfs metadata" with the given arguments
func runMetadataCmd(args ...string) error {
cmd := metadataCmd(nil)
cmd.SetArgs(args)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
return cmd.Execute()
}
func TestMetadataCommands(t *testing.T) {
// the arguments each subcommand needs besides --root and --node
subcommands := map[string][]string{
"dump": nil,
"get": {"--attribute", "user.*"},
"set": {"--attribute", "user.foo", "--value", "bar"},
}
for name, extra := range subcommands {
t.Run(name, func(t *testing.T) {
// The root is an empty directory, so the command can't read any metadata
// there, but it only gets that far with the value of --root.
root := t.TempDir()
readRoot := `could not read the metadata in "` + root + `"`
t.Run("takes --root and --node after the subcommand", func(t *testing.T) {
args := append([]string{name, "--root", root, "--node", "some-node"}, extra...)
err := runMetadataCmd(args...)
require.Error(t, err)
require.Contains(t, err.Error(), readRoot)
})
t.Run("takes --root and --node before the subcommand", func(t *testing.T) {
args := append([]string{"--root", root, "--node", "some-node", name}, extra...)
err := runMetadataCmd(args...)
require.Error(t, err)
require.Contains(t, err.Error(), readRoot)
})
t.Run("takes the short flags -r and -n", func(t *testing.T) {
args := append([]string{name, "-r", root, "-n", "some-node"}, extra...)
err := runMetadataCmd(args...)
require.Error(t, err)
require.Contains(t, err.Error(), readRoot)
})
t.Run("requires --root", func(t *testing.T) {
args := append([]string{name, "--node", "some-node"}, extra...)
err := runMetadataCmd(args...)
require.EqualError(t, err, `required flag(s) "root" not set`)
})
t.Run("requires --node", func(t *testing.T) {
args := append([]string{name, "--root", root}, extra...)
err := runMetadataCmd(args...)
require.EqualError(t, err, `required flag(s) "node" not set`)
})
})
}
}