Failed.

sirinoks

Alex Romanova

Posted on December 16, 2021

Failed.

Sometimes people don't help
Sometimes guides don't explain
Sometimes your best doesn't work out.

I first want to share some examples. I have worked my way from mocking in JS (jest) to testing in GO. I had a hard time with mocks in jest as well. I started with fixing my gaps there first. Jest has a clear structure. It has a __mocks__ folder, where you clearly put mocks in. You create a mock of the module you want to replicate there. You export it and use in other places.

//You declare what it is you want to mock
const module = jest.CreateMockFromModule("module");

//You create some functionality that will simulate wanted behavior
function someMockFunctionality () {
 Bla bla bla..
}

//You assemble it into an export to use somewhere else
module.someMockFunctionality = someMockFunctionality;
module.exports = module;
Enter fullscreen mode Exit fullscreen mode

Looks simple, structured, makes sense. I like that. If you follow a blueprint, you can make it work. As opposed to Go, which I found to not have that structure at all. It makes the concept of mocking generally blurry and unclear. I see people make tests for functions, but with really weird solutions. I can't really get the main idea and transfer it to my repo. That's what made all those tutorials hard to follow. You do a task as they explain it, but you don't actually learn the concept. Or... at least I didn't. That is why I'm showing you Jest. At least that one I figured out. I came out with something from this project.

What exactly did I attempt?

I have started with mindlessly following tutorials that should introduce me to the concept. It's the first level of everything. First you copy, then you replicate, and somewhere along the way you actually understand. I learned the most from the concept of what mocks should do. It's easiest explained when you have some sort of request/response. Could be an API, could be a database. You expect your database to return you some "apples", and you pretend it did. So you create a data structure that has "apples" in the right place. But the apples you got are not from the actual database! Sneaky. That all makes sense to me in theory. I followed some guides like that.
Problems began when I actually had to use real code. I tried finding a function that would replicate that kind of mock usage.

Let's look at some I attempted.

func NewChannelPointManager(cfg *config.Config, helixClient *helixclient.Client, db *store.Database) *ChannelPointManager {
    return &ChannelPointManager{
        cfg:         cfg,
        helixClient: helixClient,
        db:          db,
    }
}
Enter fullscreen mode Exit fullscreen mode

It uses a config, a client and a database as data. I could theoretically mock those. However, this was too much to mock as it turned out.

type ChatClient struct {
    ircClient *twitch.Client
    cfg       *config.Config
    connected chan bool
}

func NewClient(cfg *config.Config) *ChatClient {
    return &ChatClient{
        cfg:       cfg,
        connected: make(chan bool),
        ircClient: twitch.NewClient(cfg.Username, cfg.OAuth),
    }
}
Enter fullscreen mode Exit fullscreen mode

This looks doable. It expects some data we can mock, returns some data we can make.
Sure. Write a TestNewClient (t *testing T) {...}
I will also need to mock the structure of ChatClient. Oh-oh. That actually is more that it seems. I now need to work with go-twitch-irc. Sure, look at documentation.. Somewhere at this stage tings become too complicated.

It was a combination of trying to figure out a structure I needed to mock, which became too complex the more I looked into one. And me just not even being able to get how it's supposed to be done. Add unfamiliarity with the language - and I'm completely lost at every stage.

Someone help?

I think the best approach to unknown topics is to find the "guru" and ask them to lead. That's what I have been doing while I've been stuck learning on my own - trying to find help. I looked in general Go servers, asked some classmates, friends. Honestly - nobody knew enough. And those that did know never took enough effort to really explain. I would imagine if you're this cool knowledgeable programmer, you wouldn't want to mess with noobs and their easy concepts. Makes sense.
All I could find were some tutorials. However, a tutorial doesn't come with someone that could explain it.

Why did I fail?

Failure feels bad. Not necessarily is bad. Maybe I'm just trying to make is sound better than it is... In any case, failure gives us data to work with, to really figure out a better strategy and to improve. So what went wrong?

Time

One could say I have bad time management. Sure, I could have improved on that. However, the main point is not really about management. If you have 10 hours of work to do in a day, regardless of how you manage it, it will suck and will drain you. Not saying I had 10 hours - just a metaphor. My point is - it's the amount of time that was the problem. I have pushed myself to fail this task already when I selected courses for this semester. I chose too many. And I did it anyway, knowing the risk that I might have to make sarcifices. Guess this is my sarcifice.

Too much unknown

The task I chose was really not that smart. When you choose to conquer something you don't know a path towards - there is no way to even estimate how hard it would be. You either got there, or you didn't. I could have chosen something that has a clearly defined path. Something that is a common problem, something I already knew. Maybe in JS. Maybe just some kind of a bug. But nooo... I had to choose Go which I'm not familiar with. I had to choose a theme that I don't know how to solve. Again, I did suspect I would fail. It was a risk I took. After all - if I did succeed, that would make me feel pretty cool about it. Would I rather have chosen an easier task and completed it? Maybe. Perhaps my grade suffers. For that reason - of course I should have chosen an easier task. However, ignoring the grade... I'm happy with my decision. I'm not sure why. I didn't learn the thing I wanted to learn in the end. There was no reward. Perhaps I just did it for the journey. Perhaps I'm now more familiar with Go in general terms.

Might want to skip this whole Luck part...

Luck?

There's always luck to everything. I could have found my "guru". I could have found a guide that would "click". Sure, that involves luck. Not as much as my next point though..

There is a lot of randomness to my life. I'm pretty sure nobody reads this.. to put it in easier terms, there are at least 3 random parts to my day to day life.
There is a state that consistently makes me worse or better, in a pattern of which you can somewhat predict. So I could say for exampple - I'm doing great now, which means I will be doing great for one more week at the very least, and after I will be feeling terrible. That's just how it works.
Second thing is way less consistent, but works similarly. My state changes, but within hours. I can't really predict this one. You can just.. stop functioning suddenly.
Third random is hard to explain.. Let me put it this way. Imagine you had two different people living in you. That fact just by itself makes things much harder than usual. I'm putting effort into not letting their conflict be written here.

Considering those, it was just unlucky how whenever I did have time to work on this task, I was usually in the bad state, or there was always something else going on. Even now as I'm writing this. I pretty much had -50% of normal person funcitonality. And my better states were spent on other tasks which had more impact.

Yea, sure, whine, complain... Either way I didn't do good enough. And I know I could have. That's all it comes down to.

I really, really hope next semester I do better. That I wouldn't have to sarcifice as much. Because me not being able to complete this affects my own knowledge if anything else.

💖 💪 🙅 🚩
sirinoks
Alex Romanova

Posted on December 16, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related