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

feat: Add test coverage for cofidectl-debug-container #10

Merged
merged 6 commits into from
Jan 23, 2025

Conversation

nialdaly
Copy link
Contributor

Summary

  • This PR adds test coverage for cofidectl-debug-container and further decomposes main.go.
  • These changes have been tested locally (using cofidectl) and work as expected:
just integration-test single-trust-zone

...
2025/01/20 18:19:15 INFO ...pong
+ return 0
+ show_workload_status
++ kubectl get pods -l app=ping-pong-client -n demo -o 'jsonpath={.items[0].metadata.name}' --context kind-kind
+ POD_NAME=ping-pong-client-5f7cc97857-9nxtm
++ ./cofidectl workload status --namespace demo --pod-name ping-pong-client-5f7cc97857-9nxtm --trust-zone tz1
+ WORKLOAD_STATUS_RESPONSE='✅ Complete: Successfully executed emphemeral debug container in ping-pong-client-5f7cc97857-9nxtm

Trust bundles received
* spiffe://td1
    Certificate "17:26:19:31:D9:90:74:18:C1:D5:33:01:9E:3A:90:84:A0:1D:DF:45:D5:C1:8B:BC:86:F3:77:9E:92:AC:99:B3"
    is a CA certificate
    Valid from "2025-01-20T18:18:29Z" to "2025-01-21T06:18:39Z"
    Subject: SERIALNUMBER=318461288371843035447025893851366322856,CN=cofide.io,O=Cofide,C=UK
    URIs: spiffe://td1
    Signature algorithm: SHA256-RSA
    Issuer: SERIALNUMBER=318461288371843035447025893851366322856,CN=cofide.io,O=Cofide,C=UK

SVIDs received
* spiffe://td1/ns/demo/sa/ping-pong-client
    Certificate "1C:6A:EC:0E:24:86:AD:B4:51:F2:57:D8:C8:ED:95:4A:55:C9:F4:DA:40:36:C1:33:5C:D4:41:76:4E:FB:C9:C9"
    Valid from "2025-01-20T18:18:58Z" to "2025-01-20T22:19:08Z"
    Subject: O=SPIRE,C=US
    URIs: spiffe://td1/ns/demo/sa/ping-pong-client
    Signature algorithm: SHA256-RSA
    Issuer: SERIALNUMBER=318461288371843035447025893851366322856,CN=cofide.io,O=Cofide,C=UK
    SVID verified against trust bundle'
+ [[ ✅ Complete: Successfully executed emphemeral debug container in ping-pong-client-5f7cc97857-9nxtm

Trust bundles received
* spiffe://td1
    Certificate "17:26:19:31:D9:90:74:18:C1:D5:33:01:9E:3A:90:84:A0:1D:DF:45:D5:C1:8B:BC:86:F3:77:9E:92:AC:99:B3"
    is a CA certificate
    Valid from "2025-01-20T18:18:29Z" to "2025-01-21T06:18:39Z"
    Subject: SERIALNUMBER=318461288371843035447025893851366322856,CN=cofide.io,O=Cofide,C=UK
    URIs: spiffe://td1
    Signature algorithm: SHA256-RSA
    Issuer: SERIALNUMBER=318461288371843035447025893851366322856,CN=cofide.io,O=Cofide,C=UK

SVIDs received
* spiffe://td1/ns/demo/sa/ping-pong-client
    Certificate "1C:6A:EC:0E:24:86:AD:B4:51:F2:57:D8:C8:ED:95:4A:55:C9:F4:DA:40:36:C1:33:5C:D4:41:76:4E:FB:C9:C9"
    Valid from "2025-01-20T18:18:58Z" to "2025-01-20T22:19:08Z"
    Subject: O=SPIRE,C=US
    URIs: spiffe://td1/ns/demo/sa/ping-pong-client
    Signature algorithm: SHA256-RSA
    Issuer: SERIALNUMBER=318461288371843035447025893851366322856,CN=cofide.io,O=Cofide,C=UK
    SVID verified against trust bundle != *\S\V\I\D\ \v\e\r\i\f\i\e\d\ \a\g\a\i\n\s\t\ \t\r\u\s\t\ \b\u\n\d\l\e* ]]
+ echo 'cofidectl workload status successful'
cofidectl workload status successful
+ down
+ ./cofidectl down
✅ Uninstalled: Uninstallation completed for kind in tz1

+ echo 'Success!'
Success!

@nialdaly nialdaly self-assigned this Jan 20, 2025
@nialdaly nialdaly marked this pull request as ready for review January 21, 2025 10:35
return x509bundle.NewSet(bundle)
}

// captureOutput captures the output of a function and returns it as a string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change, but another way to do this is to make the code under test more amenable to testing, i.e. decouple from IO. e.g. https://dev.to/lucassha/unit-testing-stdout-in-go-1jd

@nialdaly nialdaly merged commit c48d4b2 into main Jan 23, 2025
3 checks passed
@nialdaly nialdaly deleted the feat-add-test-coverage branch January 23, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants