Lucas E M M. opinions

Integration test in a good way

code tools

This is another tale of redemption… I really enjoy minimalistic solutions and yet, I was not using for integration tests…

So, as everything that needs a start, what was the problem? For some time, I have been thinking about integration tests. What I am calling integration here means a way to test an API that goes through other APIs.

The non minimal

I tried a few approaches. One was to create a “fake” data structure that would represent the return of one API but that proved to be very difficult to insert in my coding routine.

Another approach was to use a http request client. The one I used the most was restclient mode in emacs. Which is pretty good. Here is an example of a GET request from the README:

#
# XML is supported - highlight, pretty-print
#
GET http://www.redmine.org/issues.xml?limit=10

With the mode, you have some shortcuts and can have a bunch of requests in a single file. It is pretty cool actually. The problem? it is not very good in the automation front… I did not find an easy way to run all these requests.

Well, what is the solution? Thinking minimal. Like, really minimal. I mean curl minimal.

Now, what is the problem with curl? It is tedious to make it work if you are not used to it. You have a lot of the control of how the request should be made…

Save this. We will come back to it.

The minimal

Why is it a solution, then? Because you made your request with a command line, it is very easy to automate with a script, such as a shell script.

For instance, you can create an “integration” test script like so:

# testing with 10
curl -X GET http://www.redmine.org/issues.xml?limit=10

# a test with json post
curl -X POST http://www.afakeurl.org/afakemethod --json @path-to-json-file

echo

Pretty simple if you ask me. Now, after a commit or when you feel like it, it is one command away.

Remember the problem? Well, I wonder if it really is. More control over it means that you are fully aware of what is going on. Meaning, you have a better understanding of the process. You have to study more? Sure, however I would argue it is the extra mile that could make you a better coder.

I am leaving giving my thanks to ’erica and umgeher for this small realization. Cheers!

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Integration test in a good way

Emacs? No, emacsclient!

emacs terminal

This is a shoutout for all of you who are tired of waiting emacs to load on startup or annoyed to feel forced to leave an instance open.

emacsclient can save you from that. All you have to do is to leave an daemon open. Don’t use (server-start) because that will force you to have an GUI or terminal open at all time. The solution? A command.

On your terminal (or .xsession file):

emacs --daemon

After that, you can invoke emacs GUI with emacsclient -c and emacsclient -t to open directly in the terminal. The colors probably will not match, so you can take a look here =].

Now, to make life a little bit better, you can create alias/binary

alias emt='emacsclient -t'
#!/bin/sh
emacsclient -c -F '((font . "Hack 12"))'

The latter I use as a binary in $PATH to be invoked with rofi or as a shortcut in the dwm.

Thanks Pedro for the post idea hehe.

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Emacs? No, emacsclient!

Finally, a whatsapp tui!

tui whatsapp

Ok, finally I have found a (half) solution to the whatsapp web problem. The problem being the “web” part of it… I don’t like having the browser open just to text chat. So for some time I have been looking for a text user interface solution to this.

In other words, a less RAM intensive little piece of software. The important key part for this solution is matterbridge. It is a piece of software that connects two chat enviroments that you have.

Effectively the only ones that I use are: email and whatsapp. Since this is not a viable bridging, I created a local IRC server to ensure that my chat does not go to a third party server.

Ok, now I can tell you all the softwares I used:

  1. matterbridge
  2. ergo (irc local server)
  3. weechat (but can be any irc client)

Here is an example of the matterbridge configuration for this kind of setup.

Here is the configuration of the ergo. It was the default when I cloned it

Now, start all with a script like this one.

There you go. A simple solution to an annoying problem. But it is a half solution because matterbridge only supports groups. Well, for now this is what I have. Enjoy =]

/comments ~lucasemmoreira/opinions@lists.sr.ht?Subject=Re: Finally, a whatsapp tui!