Skip to content

Commit 2cff19d

Browse files
author
Patrick J. McNerthney
committed
Implement unit test framework with initial unit tests.
1 parent e3bf500 commit 2cff19d

File tree

13 files changed

+471
-164
lines changed

13 files changed

+471
-164
lines changed

.github/workflows/ci.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ jobs:
4848
# python-version: ${{ env.PYTHON_VERSION }}
4949

5050
# - name: Setup Hatch
51-
# run: pipx install hatch==1.7.0
51+
# run: pipx install hatch==1.14.1
5252

5353
# - name: Lint
5454
# run: hatch run lint:check
5555

56-
# unit-test:
57-
# runs-on: ubuntu-24.04
58-
# steps:
59-
# - name: Checkout
60-
# uses: actions/checkout@v4
56+
unit-test:
57+
runs-on: ubuntu-24.04
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v4
6161

62-
# - name: Setup Python
63-
# uses: actions/setup-python@v5
64-
# with:
65-
# python-version: ${{ env.PYTHON_VERSION }}
62+
- name: Setup Python
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: ${{ env.PYTHON_VERSION }}
6666

67-
# - name: Setup Hatch
68-
# run: pipx install hatch==1.7.0
67+
- name: Setup Hatch
68+
run: pipx install hatch==1.14.1
6969

70-
# - name: Run Unit Tests
71-
# run: hatch run test:unit
70+
- name: Run Unit Tests
71+
run: hatch run test:unit
7272

7373
# We want to build most packages for the amd64 and arm64 architectures. To
7474
# speed this up we build single-platform packages in parallel. We then upload

examples/function-go-templating/inline/composition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
user = f"test-user-{ix}"
2424
r = self.resources[user]('iam.aws.upbound.io/v1beta1', 'User')
2525
r.metadata.labels['testing.upbound.io/example-name'] = user
26-
r.metadata.labels.dummy = r.observed.resource.metadata.labels.dummy or random.choice(['foo', 'bar', 'baz'])
26+
r.metadata.labels.dummy = r.observed.metadata.labels.dummy or random.choice(['foo', 'bar', 'baz'])
2727
r = self.resources[f"sample-access-key-{ix}"]('iam.aws.upbound.io/v1beta1', 'AccessKey')
2828
r.spec.forProvider.userSelector.matchLabels['testing.upbound.io/example-name'] = user
2929
r.spec.writeConnectionSecretToRef.namespace = 'crossplane.system'

function/composite.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def ready(self):
5454
def ready(self, ready):
5555
if ready:
5656
ready = fnv1.Ready.READY_TRUE
57-
elif ready == None or (isinstance(ready, function.protobuf.Values) and ready._type == function.protobuf.Values.Type.UNKNOWN):
57+
elif ready == None or (isinstance(ready, function.protobuf.Values) and ready._isUnknown):
5858
ready = fnv1.Ready.READY_UNSPECIFIED
5959
else:
6060
ready = fnv1.Ready.READY_FALSE
@@ -209,7 +209,7 @@ def ready(self):
209209
def ready(self, ready):
210210
if ready:
211211
ready = fnv1.Ready.READY_TRUE
212-
elif ready == None or (isinstance(ready, function.protobuf.Values) and ready._type == function.protobuf.Values.Type.UNKNOWN):
212+
elif ready == None or (isinstance(ready, function.protobuf.Values) and ready._isUnknown):
213213
ready = fnv1.Ready.READY_UNSPECIFIED
214214
else:
215215
ready = fnv1.Ready.READY_FALSE
@@ -415,7 +415,7 @@ def claim(self, claim):
415415
if bool(self):
416416
if claim:
417417
self._result.target = fnv1.Target.TARGET_COMPOSITE_AND_CLAIM
418-
elif claim == None or (isinstance(claim, function.protobuf.Values) and claim._type == function.protobuf.Values.Type.UNKNOWN):
418+
elif claim == None or (isinstance(claim, function.protobuf.Values) and claim._isUnknown):
419419
self._result.target = fnv1.Target.TARGET_UNSPECIFIED
420420
else:
421421
self._result.target = fnv1.Target.TARGET_COMPOSITE
@@ -502,7 +502,7 @@ def status(self, status):
502502
condition.status = fnv1.Status.STATUS_CONDITION_TRUE
503503
elif status == None:
504504
condition.status = fnv1.Status.STATUS_CONDITION_UNKNOWN
505-
elif isinstance(ready, function.protobuf.Values) and ready._type == function.protobuf.Values.Type.UNKNOWN:
505+
elif isinstance(status, function.protobuf.Values) and status._isUnknown:
506506
condition.status = fnv1.Status.STATUS_CONDITION_UNSPECIFIED
507507
else:
508508
condition.status = fnv1.Status.STATUS_CONDITION_FALSE
@@ -549,7 +549,7 @@ def claim(self, claim):
549549
condition = self._find_condition(True)
550550
if claim:
551551
condition.target = fnv1.Target.TARGET_COMPOSITE_AND_CLAIM
552-
elif claim == None or (isinstance(claim, function.protobuf.Values) and claim._type == function.protobuf.Values.Type.UNKNOWN):
552+
elif claim == None or (isinstance(claim, function.protobuf.Values) and claim._isUnknown):
553553
condition.target = fnv1.Target.TARGET_UNSPECIFIED
554554
else:
555555
condition.target = fnv1.Target.TARGET_COMPOSITE

function/fn.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,8 @@ def __init__(self):
2121
self.modules = {}
2222

2323
async def RunFunction(
24-
self, request: fnv1.RunFunctionRequest, context: grpc.aio.ServicerContext
24+
self, request: fnv1.RunFunctionRequest, _: grpc.aio.ServicerContext
2525
) -> fnv1.RunFunctionResponse:
26-
try:
27-
return await self.run(request, context)
28-
except Exception as e:
29-
self.logger.exception('Error during RunFuction')
30-
raise
31-
32-
async def run(self, request, context):
3326
composite = request.observed.composite.resource
3427
logger = self.logger.bind(
3528
apiVersion=composite['apiVersion'],

0 commit comments

Comments
 (0)