class Boringtun < Formula
  desc "Userspace WireGuard implementation in Rust"
  homepage "https://github.com/cloudflare/boringtun"
  url "https://github.com/cloudflare/boringtun/archive/v0.3.0.tar.gz"
  sha256 "1107b0170a33769db36876334261924edc71dfc1eb00f9b464c7d2ad6d5743d3"
  license "BSD-3-Clause"
  head "https://github.com/cloudflare/boringtun.git"

  bottle do
    sha256 cellar: :any_skip_relocation, big_sur:      "0de06cdb03839450dbe101b3f1042820f82aee7eda323039be0f48a0b2baf3e9"
    sha256 cellar: :any_skip_relocation, catalina:     "dd119327645c4905c39a4b0e6f65472690d619e127088e62573b5a0c454cbb01"
    sha256 cellar: :any_skip_relocation, mojave:       "c871b547c950e928ee065ce5dbe1442a41d65213b840654bb9e6922b7dedae0f"
    sha256 cellar: :any_skip_relocation, high_sierra:  "7e6fc1a3b6458d9df1b0c15ee53d14f0ea04e85494f306034fd8531d2ff4277c"
    sha256 cellar: :any_skip_relocation, x86_64_linux: "7d8a39ce6471c7a9e7798349efaffdc70771882984e80976969526768e97d8a4" # linuxbrew-core
  end

  depends_on "rust" => :build

  def install
    system "cargo", "install", *std_cargo_args
  end

  test do
    system "#{bin}/boringtun", "--help"
    assert_match "boringtun " + version.to_s, shell_output("#{bin}/boringtun -V").chomp
    shell_output("#{bin}/boringtun utun -v --log #{testpath}/boringtun.log", 1)
    assert_predicate testpath/"boringtun.log", :exist?
    boringtun_log = File.read(testpath/"boringtun.log")
    assert_match "Success, daemonized", boringtun_log.split("/n").first
  end
end
