From 841c2f47edfb2967f8ad18e6c9568c8dd8be6298 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Fri, 18 Mar 2022 10:48:37 +0100 Subject: Added basic ssh client to run commands --- src/main.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main.zig (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..3b16914 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,22 @@ +const std = @import("std"); + +const ssh = @import("ssh.zig"); + +pub fn main() anyerror!void { + var client = ssh.Client.init("localhost") catch unreachable; + const stdout = std.io.getStdOut(); + client.run("pwd", stdout) catch unreachable; + client.run("who", stdout) catch unreachable; + client.deinit(); +} + +test "basic test" { + // this test requires you can ssh localhost without a password prompt + // (typically by having your ssh_agent running) + var client = ssh.Client.init("localhost") catch unreachable; + var buffer = std.ArrayList(u8).init(std.testing.allocator); + defer buffer.deinit(); + client.run("echo test", buffer.writer()) catch unreachable; + try std.testing.expectEqualSlices(u8, buffer.items, "test\n"); + client.deinit(); +} -- cgit v1.2.3