diff --git a/spec/commands/mapping_create_spec.cr b/spec/commands/mapping_create_spec.cr index 42c58af..e03e191 100644 --- a/spec/commands/mapping_create_spec.cr +++ b/spec/commands/mapping_create_spec.cr @@ -3,5 +3,11 @@ require "../../src/commands/mapping_create" describe GX::Commands::MappingCreate do context "Initialization" do + it "initializes with a mock FileSystemManager and RootConfig" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + command = GX::Commands::MappingCreate.new(config) + command.should be_a(GX::Commands::MappingCreate) + end end end diff --git a/spec/commands/mapping_edit_spec.cr b/spec/commands/mapping_edit_spec.cr index a042c80..2bedf71 100644 --- a/spec/commands/mapping_edit_spec.cr +++ b/spec/commands/mapping_edit_spec.cr @@ -3,5 +3,10 @@ require "../../src/commands/mapping_edit" describe GX::Commands::MappingEdit do context "Initialization" do + it "initializes with a mock FileSystemManager" do + config = GX::Config.new + command = GX::Commands::MappingEdit.new(config) + command.should be_a(GX::Commands::MappingEdit) + end end end diff --git a/spec/commands/mapping_list_spec.cr b/spec/commands/mapping_list_spec.cr index 008862a..a0f5890 100644 --- a/spec/commands/mapping_list_spec.cr +++ b/spec/commands/mapping_list_spec.cr @@ -1,7 +1,108 @@ + require "../spec_helper" require "../../src/commands/mapping_list" +require "../../src/models/gocryptfs_config" +require "../../src/models/sshfs_config" +require "../../src/models/httpdirfs_config" describe GX::Commands::MappingList do context "Initialization" do + it "initializes with a mock FileSystemManager and RootConfig" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + command = GX::Commands::MappingList.new(config) + command.should be_a(GX::Commands::MappingList) + end + end + + context "Functioning" do + it "lists mappings when there are no filesystems" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + command = GX::Commands::MappingList.new(config) + + output = capture_output do + command.execute + end + + output.should include("TYPE") + output.should include("NAME") + output.should include("MOUNTED") + end + + it "lists mappings when there are multiple filesystems" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + + gocryptfs_config = GX::Models::GoCryptFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "gocryptfs", + name: "test_gocryptfs", + encrypted_path: "/encrypted/path" + ) + ) + sshfs_config = GX::Models::SshFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "sshfs", + name: "test_sshfs", + remote_user: "user", + remote_host: "host", + remote_path: "/remote/path" + ) + ) + httpdirfs_config = GX::Models::HttpDirFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "httpdirfs", + name: "test_httpdirfs", + url: "http://example.com" + ) + ) + + root_config.add_filesystem(gocryptfs_config) + root_config.add_filesystem(sshfs_config) + root_config.add_filesystem(httpdirfs_config) + + command = GX::Commands::MappingList.new(config) + + output = capture_output do + command.execute + end + + output.should include("gocryptfs") + output.should include("test_gocryptfs") + output.should include("false") + + output.should include("sshfs") + output.should include("test_sshfs") + output.should include("false") + + output.should include("httpdirfs") + output.should include("test_httpdirfs") + output.should include("false") + end + + it "ensures the output format is correct" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + config.instance_variable_set("@root", root_config) + + gocryptfs_config = GX::Models::GoCryptFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "gocryptfs", + name: "test_gocryptfs", + encrypted_path: "/encrypted/path" + ) + ) + root_config.add_filesystem(gocryptfs_config) + + command = GX::Commands::MappingList.new(config) + + output = capture_output do + command.execute + end + + output.should match(/TYPE\s+NAME\s+MOUNTED/) + output.should match(/gocryptfs\s+test_gocryptfs\s+false/) + end end end