Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bats file detik and support #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/test-brew-formulas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: test-formulas

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
test-formulas:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Brew version output
run: brew --version
- name: INSTALL bats-core
run: brew uninstall bats; brew install bats-core
- name: Bats-support AUDIT
run: brew audit --new-formula --formula Formula/bats-support.rb
- name: Bats-support INSTALL
run: brew install --build-from-source --verbose bats-support
- name: Bats-support TEST
run: brew test Formula/bats-support.rb
- name: Bats-assert AUDIT
run: brew audit --new-formula --formula Formula/bats-assert.rb
- name: Bats-assert INSTALL
run: brew install --build-from-source --verbose bats-assert
- name: Bats-assert TEST
run: brew test Formula/bats-assert.rb
- name: Bats-file AUDIT
run: brew audit --new-formula --formula Formula/bats-file.rb
- name: Bats-file INSTALL
run: brew install --build-from-source --verbose bats-file
- name: Bats-file TEST
run: brew test Formula/bats-file.rb
- name: Bats-detik AUDIT
run: brew audit --new-formula --formula Formula/bats-detik.rb
- name: Bats-detik INSTALL
run: brew install --build-from-source --verbose bats-detik
- name: Bats-detik TEST
run: brew test Formula/bats-detik.rb
68 changes: 42 additions & 26 deletions Formula/bats-assert.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
class BatsAssert < Formula
desc "Common assertions for Bats"
homepage "https://github.com/bats-core/homebrew-bats-core"
url "https://github.com/bats-core/bats-assert/archive/refs/tags/v2.0.0.tar.gz"
head "https://github.com/bats-core/bats-assert.git"
version "v2.0.0"
sha256 "15dbf1abb98db785323b9327c86ee2b3114541fe5aa150c410a1632ec06d9903"
license "CC0 1.0 Universal"
desc "Common assertions for Bats"
homepage "https://github.com/bats-core/bats-assert"
url "https://github.com/bats-core/bats-assert/archive/refs/tags/v2.0.0.tar.gz"
sha256 "15dbf1abb98db785323b9327c86ee2b3114541fe5aa150c410a1632ec06d9903"
license "MIT"
head "https://github.com/bats-core/bats-assert.git", branch: "master"

def install
mkdir "bats-assert"
mv "load.bash", "bats-assert/"
mv "src", "bats-assert/"
mv "test", "bats-assert/"
lib.install "bats-assert"
end
def install
mkdir "bats-assert"
mv "load.bash", "bats-assert/"
mv "src", "bats-assert/"
mv "test", "bats-assert/"
lib.install "bats-assert"
end

def caveats
<<~EOS
To load the bats-assert lib in your bats test:
load '#{HOMEBREW_PREFIX}/lib/bats-support/load.bash'
load '#{HOMEBREW_PREFIX}/lib/bats-assert/load.bash'
EOS
end
def caveats
<<~EOS
To load the bats-assert lib in your bats test:
load '#{HOMEBREW_PREFIX}/lib/bats-support/load.bash'
load '#{HOMEBREW_PREFIX}/lib/bats-assert/load.bash'
EOS
end

test do
ENV["TEST_DEPS_DIR"] = "#{HOMEBREW_PREFIX}/lib"
system "bats", "#{lib}/bats-assert/test"
end
end
test do
(testpath/"test.bats").write <<~EOS
setup() {
load '#{HOMEBREW_PREFIX}/lib/bats-support/load.bash'
load '#{HOMEBREW_PREFIX}/lib/bats-assert/load.bash'
}

@test "assert true" {
assert true
}

@test "refute false" {
refute false
}

@test "assert equal" {
assert_equal '42' '42'
}
EOS
ENV["TEST_DEPS_DIR"] = "#{HOMEBREW_PREFIX}/lib"
system "bats", "test.bats"
end
end
74 changes: 74 additions & 0 deletions Formula/bats-detik.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class BatsDetik < Formula
desc "Library to ease e2e tests of applications in K8s environments"
homepage "https://github.com/bats-core/bats-detik"
url "https://github.com/bats-core/bats-detik/archive/refs/tags/v1.1.0.tar.gz"
sha256 "1467f5f1d51211a0cb163cfceee65796e710fe8b3f4b6731d404eb075e9147e3"
license "MIT"
head "https://github.com/bats-core/bats-detik.git", branch: "master"

def install
mkdir "bats-detik"
mv "lib/detik.bash", "bats-detik/"
mv "lib/utils.bash", "bats-detik/"
mv "lib/linter.bash", "bats-detik/"
mv "examples", "bats-detik/"
mv "tests", "bats-detik/"
mv "Dockerfile", "bats-detik/"
lib.install "bats-detik"
end

def caveats
<<~EOS
To load the bats-detik lib in your bats test:

load '#{HOMEBREW_PREFIX}/lib/bats-detik/utils.bash'
load '#{HOMEBREW_PREFIX}/lib/bats-detik/detik.bash'

DETIK_CLIENT_NAME="kubectl"
EOS
end

test do
(testpath/"test.bats").write <<~EOS
setup() {
load '#{HOMEBREW_PREFIX}/lib/bats-detik/utils.bash'
load '#{HOMEBREW_PREFIX}/lib/bats-detik/detik.bash'
}

DETIK_CLIENT_NAME="mytest"
DETIK_CLIENT_NAMESPACE=""
mytest() {
# The namespace should not appear (it is set in 1st position)
[[ "$1" != "--namespace=test_ns" ]] || return 1
# Return the result
echo -e "NAME PROP\nnginx-deployment-75675f5897-6dg9r Running\nnginx-deployment-75675f5897-gstkw Running"
}

@test "verifying the number of PODs with the lower-case syntax (exact number, plural)" {
run verify "there are 2 pods named 'nginx'"
[ "$status" -eq 0 ]
[ ${#lines[@]} -eq 2 ]
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
[ "${lines[1]}" = "Found 2 pods named nginx (as expected)." ]
}

@test "verifying the number of PODs with the lower-case syntax (exact number, singular)" {
run verify "there is 1 pod named 'nginx-deployment-75675f5897-6dg9r'"
[ "$status" -eq 0 ]
[ ${#lines[@]} -eq 2 ]
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
[ "${lines[1]}" = "Found 1 pod named nginx-deployment-75675f5897-6dg9r (as expected)." ]
}

@test "verifying the number of PODs with an invalid name" {
run verify "There are 2 pods named 'nginx-inexisting'"
[ "$status" -eq 3 ]
[ ${#lines[@]} -eq 2 ]
[ "${lines[0]}" = "Valid expression. Verification in progress..." ]
[ "${lines[1]}" = "Found 0 pods named nginx-inexisting (instead of 2 expected)." ]
}
EOS
ENV["TEST_DEPS_DIR"] = "#{HOMEBREW_PREFIX}/lib"
system "bats", "test.bats"
end
end
56 changes: 56 additions & 0 deletions Formula/bats-file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class BatsFile < Formula
desc "Common filesystem assertions for Bats"
homepage "https://github.com/bats-core/bats-file"
url "https://github.com/bats-core/bats-file/archive/refs/tags/v0.3.0.tar.gz"
sha256 "54d1c8b1908608aef8e46ac17d4001a75119e279662aeac4e5859ce780515362"
license "MIT"
head "https://github.com/bats-core/bats-file.git", branch: "master"

def install
mkdir "bats-file"
mv "load.bash", "bats-file/"
mv "src", "bats-file/"
mv "test", "bats-file/"
lib.install "bats-file"
end

def caveats
<<~EOS

To load the bats-file lib in your bats test:

load '#{HOMEBREW_PREFIX}/lib/bats-support/load.bash'
load '#{HOMEBREW_PREFIX}/lib/bats-file/load.bash'
EOS
end

test do
(testpath/"test.bats").write <<~EOS
setup() {
load '#{HOMEBREW_PREFIX}/lib/bats-support/load.bash'
load '#{HOMEBREW_PREFIX}/lib/bats-file/load.bash'
}

@test 'assert_file_exist() <file>: returns 0 if <file> exists' {
local -r file="myfile"
run assert_file_exist "$file"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
}

@test 'assert_file_exist() <file>: returns 1 and displays path if <file> does not exist' {
local -r file="mydir"
run assert_file_exist "$file"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[0]}" == '-- file does not exist --' ]
[ "${lines[1]}" == "path : $file" ]
[ "${lines[2]}" == '--' ]
}
EOS
ENV["TEST_DEPS_DIR"] = "#{HOMEBREW_PREFIX}/lib"
File.write("myfile", "")
Dir.mkdir "mydir"
system "bats", "test.bats"
end
end
31 changes: 31 additions & 0 deletions Formula/bats-support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class BatsSupport < Formula
desc "Supporting library for Bats test helpers"
homepage "https://github.com/bats-core/homebrew-bats-core"
url "https://github.com/bats-core/bats-support/archive/refs/tags/v0.3.0.tar.gz"
sha256 "7815237aafeb42ddcc1b8c698fc5808026d33317d8701d5ec2396e9634e2918f"
license "MIT"
head "https://github.com/bats-core/bats-support.git", branch: "master"
depends_on "bats-core"

def install
mkdir "bats-support"
mv "load.bash", "bats-support/"
mv "src", "bats-support/"
mv "test", "bats-support/"
lib.install "bats-support"
end

def caveats
<<~EOS

To load the bats-support lib in your bats test:

load '#{HOMEBREW_PREFIX}/lib/bats-support/load.bash'
EOS
end

test do
ENV["TEST_DEPS_DIR"] = "#{HOMEBREW_PREFIX}/lib"
system "bats", "#{lib}/bats-support/test"
end
end