-
Notifications
You must be signed in to change notification settings - Fork 441
Better SCM CI Integration Testing
Most of the functionality can be tested by faking the payload sent by an SCM event. You can simply run a curl
command against a local endpoint.
-
Create a personal access token on GitHub with the
public_repo
scope. -
Create a workflow token on OBS with the
scm_token
containing the token created on GitHub. -
Take the payload of a recent delivery from one of the OBS webhooks and save it in a file like
payload.json
. -
Create a
workflows.yml
file undersrc/api/
with the workflows and steps you want to test (you can use our OBS workflow if needed). Change the methodWorkflows::YAMLDownloader#call
to instead returnFile.open('workflows.yml')
. This is to use theworkflows.yml
you created. -
In your local OBS instance, create the project/package/repositories/architectures needed for the
workflows.yml
you created in the previous step. -
Change the method
TriggerControllerService::TokenExtractor#valid_signature?
to returntrue
. This is to circumvent the authentication, unless you want to test that. -
Send a POST request with
curl
. Change the ALL CAPS to the according values. See the example below:GitHub:
curl -X POST 'http://localhost:3000/trigger/workflow?id=YOUR_WORKFLOW_TOKEN_ID' --data @payload.json --header 'X-GitHub-Event: SCM_EVENT_YOU_WANT' --header 'Content-Type: application/json' --header 'X-Hub-Signature-256: sha256=YOUR_WORKFLOW_TOKEN_STRING'
GitLab:
curl -X POST 'http://localhost:3000/trigger/workflow?id=YOUR_WORKFLOW_TOKEN_ID' --data @payload.json --header 'X-Gitlab-Event: SCM_EVENT_YOU_WANT' --header 'Content-Type: application/json' --header 'X-Gitlab-Token: YOUR_WORKFLOW_TOKEN_STRING'
Gitea:
curl -X POST 'http://localhost:3000/trigger/workflow?id=YOUR_WORKFLOW_TOKEN_ID' --data @payload.json --header 'X-GitHub-Event: SCM_EVENT_YOU_WANT' --header 'X-Gitea-Event: SCM_EVENT_YOU_WANT' --header 'Content-Type: application/json' --header 'X-Hub-Signature-256: sha256=YOUR_WORKFLOW_TOKEN_STRING'
In case it is extremely needed to connect your local application with a real SCM, use ngrok
as we describe here:
Warning: always log out of your VPN before starting using ngrok.
- Create an account in https://ngrok.com and follow the instructions, which are basically:
- Download ngrok.zip and unzip it
- Add the
authtoken
with./ngrok authtoken <authtoken>
- Run
ngrok http 3000
to set the tunnel. - A UI will be displayed in your terminal with the public URL of your tunnel, copy it.
- Add the host of the public URL to
config/environments/development.rb
. Example:config.hosts << "2406-79-153-113-247.ngrok.io"
- Restart the local server.
- Both
localhost:3000
and the public URL should be accessible from your browser. - Follow this guide to integrate your locally-running application with GitHub, keeping this in mind:
- Create the OBS workflow token locally
- The "Payload URL" field in GitHub webhook should look like:
https://2406-79-153-113-247.ngrok.io/trigger/workflow?id=0
- Open a new PR towards the GitHub repository where you configured the webhook, so you will see that the new subproject has been created in the application running locally.
- Development Environment Overview
- Development Environment Tips & Tricks
- Spec-Tips
- Code Style
- Rubocop
- Testing with VCR
- Authentication
- Authorization
- Autocomplete
- BS Requests
- Events
- ProjectLog
- Notifications
- Feature Toggles
- Build Results
- Attrib classes
- Flags
- The BackendPackage Cache
- Maintenance classes
- Cloud uploader
- Delayed Jobs
- Staging Workflow
- StatusHistory
- OBS API
- Owner Search
- Search
- Links
- Distributions
- Repository
- Data Migrations
- next_rails
- Ruby Update
- Rails Profiling
- Installing a local LDAP-server
- Remote Pairing Setup Guide
- Factory Dashboard
- osc
- Setup an OBS Development Environment on macOS
- Run OpenQA smoketest locally
- Responsive Guidelines
- Importing database dumps
- Problem Statement & Solution
- Kickoff New Stuff
- New Swagger API doc
- Documentation and Communication
- GitHub Actions
- How to Introduce Software Design Patterns
- Query Objects
- Services
- View Components
- RFC: Core Components
- RFC: Decorator Pattern
- RFC: Backend models