Skip to content

Commit

Permalink
Move test to python
Browse files Browse the repository at this point in the history
  • Loading branch information
wrobstory committed Oct 5, 2023
1 parent c33d6cb commit dcc2c43
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
- uses: actions/checkout@v4
- name: example
shell: bash
run: scripts/ci-test.sh
run: scripts/ci-test.py
31 changes: 0 additions & 31 deletions scripts/ci-test.sh

This file was deleted.

61 changes: 61 additions & 0 deletions scripts/ci_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/python3

import json
import os
import subprocess

# Navigate to tests/simple_flow
os.chdir('tests/simple_flow')

# Run bazel clean --expunge
subprocess.run(['bazel', 'clean', '--expunge'], check=True)

# Run bazel build ...
subprocess.run(['bazel', 'build', '...'], check=True)

# Calculate SHA_A
with open('bazel-bin/test_assemble_simple_merger_manifest.json', 'rb') as f:
SHA_A = subprocess.run(['shasum', '-a', '256'], stdin=f, capture_output=True, check=True).stdout.strip()

# Load JSON file
with open('bazel-bin/test_assemble_simple_merger_config.json') as json_file:
data = json.load(json_file)

# Check Cmd, Labels, and User fields
cmd = data['config']['Cmd']
labels = data['config']['Labels']
user = data['config']['User']

# Expected values
expected_cmd = ["/usr/bin/my_app"]
expected_labels = {"label1": "foo", "label2": "bar"}
expected_user = "nfbasic"

assert(cmd == expected_cmd)
assert(labels == expected_labels)
assert(user == expected_user)

# Run bazel clean --expunge
subprocess.run(['bazel', 'clean', '--expunge'], check=True)

# Run bazel build ...
subprocess.run(['bazel', 'build', '...'], check=True)

# Calculate SHA_B
with open('bazel-bin/test_assemble_simple_merger_manifest.json', 'rb') as f:
SHA_B = subprocess.run(['shasum', '-a', '256'], stdin=f, capture_output=True, check=True).stdout.strip()

# Compare SHA_A and SHA_B
if SHA_A != SHA_B:
print("expected same sha but got")
print(SHA_A)
print(SHA_B)
exit(1)
else:
print(f"[ok] SHA256 matched {SHA_A}")

# Navigate to tests/override_tools
os.chdir('../../tests/override_tools')

# Run bazel query ...
subprocess.run(['bazel', 'query', '...'], check=True)
20 changes: 20 additions & 0 deletions tests/simple_flow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ load(
"@com_github_bazeltools_rules_minidock//minidock:container_push.bzl",
"container_push",
)
load(
"@com_github_bazeltools_rules_minidock//minidock:container_config.bzl",
"container_config",
)

container_data(
name = "file_a_data",
Expand All @@ -26,12 +30,28 @@ container_data(
files = ["file_b.txt"],
)

container_config(
name = "user_and_app",
user = "nfbasic",
cmd = [
"/usr/bin/my_app",
],
)

container_config(
name = "labels",
labels = {"label1": "foo",
"label2": "bar"}
)

container_compose(
name = "test_simple_imagen",
base = "@bazel_320//:metadata",
layers = [
":file_a_data",
":file_b_data",
":user_and_app",
":labels"
],
)

Expand Down

0 comments on commit dcc2c43

Please sign in to comment.