Test Data Slack Command — Part 1

Automating test data creation through tool integration.

Janna Loeffler
Equinox Media Tech
6 min readJun 3, 2021

--

What does GitHub, Lambda, Postman, and Slack all have in common? It may sound like a bad joke but integrating these tools helped the Test Engineering team at Equinox Media provide Test User credentials to the masses.

Like most things, going through the API is a lot faster than trying to input information and walk through a UI. If you have ever tried to create a new account for anything, you know this can be a tedious task. As natural problem solvers the Test Engineering team put together a Postman collection that we could run and create a test account in our staging environment on the fly. But why stop there?

We quickly realized that as awesome as it was for us, there were people who needed to create test accounts that didn’t have access to or didn’t understand Postman. In order to better serve our teammates, we decided to integrate our workplace tools in order to serve the greater good. So, without further ado, here is how we got it done.

It all starts with Postman. In our case, there were two endpoints we needed to hit:

Like most applications, a user needs a username and password to log into our application. We got our Postman collection up and running so that a user was created with a password. That information was all handled through Postman variables and POST requests. Now we needed to get that information to our users. This is where we came upon our first Slack integration.

Postman has a great feature where you can run some tests after your requests. Test scripts are written in JavaScript and are run after a response is received. It’s super flexible though on what is considered a “test.” We took advantage of this by using this feature to send a request to Slack.

As you can see (sensitive information has been blurred) we are using Postman to send a request to a Slack endpoint. The result of this being that a message is sent to a specific Slack channel, notifying a person that the request has been completed and providing them with the desired login credentials. In Slack looks something like this:

In order to get the necessary Slack integration, we needed to create a Slack App and install it in our organization’s Slack workspace. We decided to call our Slack App “create-eqxplus-test-user.” I’m not going to go into the details of that as there is great documentation out there at: https://api.slack.com/messaging/webhooks.

Step one: communicate out results was completed. However, we still had a few more challenges to tackle including ease of use and getting the username to personalize the message. We decided to start with ease of use.

One of the larger hurdles we had to face was the fact that not everyone in the company knows Postman. We are also using the free version of Postman, so we couldn’t easily share this collection out to the company through Postman. We decided to be good citizens by exporting the collection and environment information and putting it into a GitHub repository. That way we could leverage version control and the collection wouldn’t get lost on someone’s machine. The side advantage of this is that it also allowed us to work with GitHub Actions.

If you are not familiar with GitHub Actions, GitHub Actions allows you to automate your software development tasks. You can learn more about them here: https://github.com/features/actions. Even though this use case isn’t necessarily a software development task, we still needed some automation. GitHub Actions lets you do this through .yaml files. So basically anything that you can do through the CLI, you can automate using GitHub Actions. This is where Newman comes into play.

We needed a way to run our Postman collection through the CLI. Luckily, there is already a free tool out there that helps with this: https://learning.postman.com/docs/running-collections/using-newman-cli/command-line-integration-with-newman/ . Once again, I’m not going to go through the details as this is pretty well documented on its own. What I will, mostly, show you is the .yaml file that executes our Postman collection that integrates with Slack.

Now we have our collection in GitHub and we have a push button way of executing it through doing a manual dispatch of a GitHub Action. However, this would mean people would still need to know how to login to GitHub and run a GitHub Action. I wanted to make it even more simple than that. This is where our next Slack integration comes into play, Slack Slash Commands.

Slack Slash Commands allow you to interact with a Slack App. We had already created a Slack App for the web hook, now we just needed to enable Slash Commands for that app. You can find out more about that here: https://api.slack.com/interactivity/slash-commands. The important thing to focus on here is that when a Slack Command is invoked, it sends an HTTP POST request to a URL you provide when setting up the Slash Command. The payload sent with that contains the user ID of the person who invoked the Slash Command. Boom! That’s how we get our username to custom our Slack Message. Even better is that I found out that I could run a GitHub action through a HTTP POST request: https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event .

At this point in time I thought I was golden. I figured I could just put the GitHub API endpoint in the Slack App Slash Command URL and be all set, but I was mistaken. In order to use that endpoint, I need to authenticate into GitHub. That’s going to take more code work than entering a single URL into the Slack App Slash Command configuration. What I quickly realized was that I needed a separate endpoint to configure the Slack Slash Command that would then authenticate into GitHub, parse out the username from the Slash Command payload, and send a request to kick off the GitHub Action. Instead of creating my own web server to handle all of this, I decided to leverage the power of Lambda. So, we get an architecture as follows:

Now, as much as I would love to share my Lambda function with you, I unfortunately can’t. There is too much proprietary information in there to share the gist, but here is what I can share.

  1. Authenticate into GitHub using Octokit
  2. Decode the Slack Payload and get the user_id
  3. Send request to GitHub to trigger workflow that creates a test user, passing the Slack user_id

Now anyone in our organization’s Slack workspace can invoke “/create-eqxplus-test-user” and see:

As you might have noticed, the article is titled Part 1. This is because after creating this Slack command, I was flooded with feature requests. This has prompted me to expand this Slack App into an interactive chatbot that will allow people to not only create test users, but fulfill other common requests as well!

Stay tuned for Part 2 which will come once we have completed that work.

--

--

Janna Loeffler
Equinox Media Tech

Janna Loeffler is the Director of Test Engineering at Equinox Media. She has a passion for helping people build high-quality software more efficiently.