-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an integration test so we don't break things or whatever
- Loading branch information
Showing
13 changed files
with
391 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[run] | ||
branch = True | ||
source = | ||
fireconfig | ||
omit = | ||
fireconfig/k8s/* | ||
|
||
[report] | ||
exclude_lines = | ||
# Have to re-enable the standard pragma | ||
\#\s*pragma: no cover | ||
|
||
# Don't complain if tests don't hit defensive assertion code: | ||
^\s*raise AssertionError\b | ||
^\s*raise NotImplementedError\b | ||
^\s*return NotImplemented\b | ||
^\s*raise$ | ||
|
||
# Don't complain if non-runnable code isn't run: | ||
^if __name__ == ['"]__main__['"]:$ | ||
# vim:ft=dosini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[flake8] | ||
max-line-length = 121 | ||
ignore = E121,E123,E126,E226,E24,E704,W503,W504,E702,E703,E741,W605 | ||
extend-ignore = E702,E703,E741,W605,E124,E128 | ||
extend-exclude = fireconfig/k8s/* | ||
|
||
# vim:ft=dosini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out master | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
|
||
- name: Run tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
__pycache__ | ||
.*sw[op] | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.PHONY: test | ||
|
||
test: | ||
poetry run coverage erase | ||
poetry run coverage run -m pytest -svv itests | ||
poetry run coverage report --show-missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: the-namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: deployment1-svc | ||
namespace: the-namespace | ||
spec: | ||
ports: | ||
- port: 8086 | ||
targetPort: 8086 | ||
selector: | ||
fireconfig.io/app: deployment1 | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: fc-test-package-sa | ||
namespace: the-namespace | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: fc-test-package-crb | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-admin | ||
subjects: | ||
- kind: ServiceAccount | ||
name: fc-test-package-sa | ||
namespace: the-namespace | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: fc-test-package-the-volume-name | ||
namespace: the-namespace | ||
data: | ||
foo.yml: bar | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: fc-test-package-other_name | ||
namespace: the-namespace | ||
data: | ||
bar.yml: asdf | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: fc-test-package-depl | ||
namespace: the-namespace | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
fireconfig.io/app: deployment1 | ||
template: | ||
metadata: | ||
labels: | ||
fireconfig.io/app: deployment1 | ||
spec: | ||
containers: | ||
- args: | ||
- /run.sh | ||
env: | ||
- name: POD_OWNER | ||
value: fc-test-package-depl | ||
image: test:latest | ||
name: container1 | ||
ports: | ||
- containerPort: 8086 | ||
securityContext: | ||
capabilities: | ||
add: | ||
- SYS_PTRACE | ||
volumeMounts: | ||
- mountPath: /mount/path | ||
name: the-volume-name | ||
- mountPath: /mount/path | ||
name: other_name | ||
nodeSelector: | ||
type: kind-worker | ||
serviceAccountName: fc-test-package-sa | ||
volumes: | ||
- configMap: | ||
items: | ||
- key: foo.yml | ||
path: foo.yml | ||
name: fc-test-package-the-volume-name | ||
name: the-volume-name | ||
- configMap: | ||
items: | ||
- key: bar.yml | ||
path: bar.yml | ||
name: fc-test-package-other_name | ||
name: other_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
```mermaid | ||
%%{init: {'themeVariables': {'mainBkg': '#ddd'}}}%% | ||
graph LR | ||
|
||
classDef default color:#000 | ||
subgraph global | ||
direction LR | ||
global/the-namespace[<b>Namespace</b><br>the-namespace] | ||
%% DELETED OBJECTS START | ||
%% DELETED OBJECTS END | ||
end | ||
|
||
subgraph fc-test-package | ||
direction LR | ||
the-namespace/deployment1-svc[<b>Service</b><br>deployment1-svc] | ||
the-namespace/fc-test-package-depl[<b>Deployment</b><br>fc-test-package-depl] | ||
the-namespace/fc-test-package-sa[<b>ServiceAccount</b><br>fc-test-package-sa] | ||
fc-test-package/fc-test-package-crb[<b>ClusterRoleBinding</b><br>fc-test-package-crb] | ||
the-namespace/fc-test-package-the-volume-name[<b>ConfigMap</b><br>fc-test-package-the-volume-name] | ||
the-namespace/fc-test-package-other_name[<b>ConfigMap</b><br>fc-test-package-other_name] | ||
the-namespace/fc-test-package-sa--->the-namespace/fc-test-package-depl | ||
fc-test-package/fc-test-package-crb--->the-namespace/fc-test-package-depl | ||
the-namespace/fc-test-package-the-volume-name--->the-namespace/fc-test-package-depl | ||
the-namespace/fc-test-package-other_name--->the-namespace/fc-test-package-depl | ||
%% DELETED OBJECTS START | ||
%% DELETED OBJECTS END | ||
end | ||
|
||
global--->fc-test-package | ||
|
||
%% STYLE DEFINITIONS START | ||
%% STYLE DEFINITIONS END | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from constructs import Construct | ||
|
||
import fireconfig as fire | ||
from fireconfig.types import Capability | ||
|
||
GRPC_PORT = 8086 | ||
OUTPUT_DIR = "itests/output" | ||
|
||
|
||
def _make_deployment(): | ||
volumes = (fire.VolumesBuilder() | ||
.with_config_map("the-volume-name", "/mount/path", {"foo.yml": "bar"}) | ||
.with_config_map("other_name", "/mount/path", {"bar.yml": "asdf"}) | ||
) | ||
|
||
container = fire.ContainerBuilder( | ||
name="container1", | ||
image="test:latest", | ||
args=["/run.sh"], | ||
).with_ports(GRPC_PORT).with_security_context(Capability.DEBUG).with_volumes(volumes) | ||
|
||
return (fire.DeploymentBuilder(app_label="deployment1") | ||
.with_containers(container) | ||
.with_service() | ||
.with_service_account_and_role_binding("cluster-admin", True) | ||
.with_node_selector("type", "kind-worker") | ||
) | ||
|
||
|
||
class FCTestPackage(fire.AppPackage): | ||
def __init__(self): | ||
self._depl = _make_deployment() | ||
|
||
def compile(self, chart: Construct): | ||
self._depl.build(chart) | ||
|
||
@property | ||
def id(self): | ||
return "fc-test-package" | ||
|
||
|
||
def test_deployment(): | ||
old_dag_filename = f"{OUTPUT_DIR}/dag.mermaid" | ||
dag, diff = fire.compile( | ||
{"the-namespace": [FCTestPackage()]}, | ||
dag_filename=old_dag_filename, | ||
cdk8s_outdir=OUTPUT_DIR | ||
) | ||
|
||
assert diff == "" | ||
with open(old_dag_filename) as f: | ||
# the resulting dag file has a blank newline which gets stripped by pre-commit, | ||
# so compare everything except for that very last character | ||
assert dag[:-1] == f.read() |
Oops, something went wrong.