<div dir="ltr"><div><div><div><div><div>Thank you Thomas , Todd and Pavol for for your suggestions - <br><br></div>The takeaways I have from the above discussion is that both are equally important !<br><br></div>In this sprint we have contributed tests which interact with Github. I think that's a good start given the fact that our first objective is to get things working, and after that we should optimize our test case design to have it run in 'firewalled' environments as well ( at least have a fallback ). <br><br>We have already done this for most tests in other areas where external resources are involved. What makes it difficult to do in case of OAuth2.0 is that we also need to mock a workflow where a user accepts a set of permissions. There is a write operation involved unlike the other cases ( like remote work item integration ) which are mostly about reading.<br><br></div>I've opened an issue here [1] to track design discussions for this.<br><br><br>[1] <a href="https://github.com/almighty/almighty-core/issues/368">https://github.com/almighty/almighty-core/issues/368</a> <br><br></div>Thanks,<br></div>Shoubhik<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 13, 2016 at 8:06 PM, Pavol Pitonak <span dir="ltr"><<a href="mailto:ppitonak@redhat.com" target="_blank">ppitonak@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>I agree that both types of tests make sense.<br><br></div>For unit tests, if I understand it correctly, you are using library go-github. In this case, we can expect that the library is working correctly and therefore I wouldn't test/mock Github API directly (but I advise to do audit of go-github test coverage). In Almighty core unit tests, you only need to make sure that correct function of go-github library is called with correct parameters and you fake the response if necessary (e.g. if you want to simulate errors).<br><br></div>Regards,<br></div>Pavol<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 13, 2016 at 1:54 PM, Todd Mancini <span dir="ltr"><<a href="mailto:tmancini@redhat.com" target="_blank">tmancini@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div style="font-family:Calibri,sans-serif;font-size:11pt">I agree. I'd go one step further -- a mock should be able to produce the same kinds of errors as the real object, and there should be unit tests for those conditions so we know we handle failures gracefully.<br><br>Sent from my phone, so anticipate hilarious autocorrects</div></div><div dir="ltr"><hr><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">From: </span><span style="font-family:Calibri,sans-serif;font-size:11pt"><a href="mailto:tmader@redhat.com" target="_blank">Thomas Mäder</a></span><br><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">Sent: </span><span style="font-family:Calibri,sans-serif;font-size:11pt">‎10/‎13/‎2016 4:00 AM</span><br><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">To: </span><span style="font-family:Calibri,sans-serif;font-size:11pt"><a href="mailto:shbose@redhat.com" target="_blank">Shoubhik Bose</a>; <a href="mailto:almighty-public@redhat.com" target="_blank">ALMighty-public</a></span><br><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">Subject: </span><span style="font-family:Calibri,sans-serif;font-size:11pt">Re: [almighty] Approach for writing unit tests for Github OAuth2.0 auth</span><br><br></div></div><div class="m_-5097755231402078698HOEnZb"><div class="m_-5097755231402078698h5">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <p>Hi Shoubhik,</p>
    <p>I think both kinds of test have their place. If we want to verify
      that our code does what we want it to do (tests as specification),
      it makes a lot of sense to test very specific interactions. Since
      OAuth is basically a sequence of requests to our server, there
      really isn't a need to "mock" anything: it's just a sequence of
      http requests where we need to check the proper responses. I would
      want this test to work without needing anything outside my local
      machine, so that I can work when I'm offline.<br>
    </p>
    <p>However, in the wild, many things may go wrong: it might be as
      stupid as a corporate firewall filtering out some headers from
      requests. Also, our test might not accurately represent the
      behaviour of Github OAuth in every detail. Having that safety net
      seems valuable to me. It may be hard to cover every use case in
      these tests. We may want to start with covering 1-2 basic flows
      and add more as regression tests as we go along.<br>
    </p>
    <p>What I think is important for productivity is that I can run all
      the local tests while I am developing in a simple way. </p>
    <p>just my 0.02€<br>
    </p>
    <p>/Thomas<br>
    </p>
    <p><br>
    </p>
    <div class="m_-5097755231402078698m_-8241620048218316063moz-cite-prefix">On 10/12/2016 05:55 PM, Shoubhik Bose
      wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>
                    <div>Hi folks,<br>
                      <br>
                    </div>
                    This is an extension to a discussion we were having
                    about what would be the apt approach to write tests
                    for Github authentication on the alm core ( backend
                    ).<br>
                    <br>
                  </div>
                  We've written a bunch of tests which checks if our
                  code does the Github OAuth flow correctly.<br>
                  <br>
                </div>
                However the alternate school of thought is:<br>
                <br>
              </div>
              Should we have a 'mock' Github OAuth provider to also test
              our code, since conventionally tests should not be
              depending on external systems.<br>
              <br>
            </div>
            On the flip-side, if test failures are not caught with a
            real Github OAuth provider we might ending up chasing bugs
            in production.<br>
            <br>
          </div>
          Let me know your thoughts.<br>
          <br>
          <br>
          - <br>
        </div>
        Shoubhik <br>
      </div>
      <br>
      <fieldset class="m_-5097755231402078698m_-8241620048218316063mimeAttachmentHeader"></fieldset>
      <br>
      <pre>______________________________<wbr>_________________
almighty-public mailing list
<a class="m_-5097755231402078698m_-8241620048218316063moz-txt-link-abbreviated" href="mailto:almighty-public@redhat.com" target="_blank">almighty-public@redhat.com</a>
<a class="m_-5097755231402078698m_-8241620048218316063moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/almighty-public" target="_blank">https://www.redhat.com/mailman<wbr>/listinfo/almighty-public</a>
</pre>
    </blockquote>
    <br>
  </div>

</div></div><br>______________________________<wbr>_________________<br>
almighty-public mailing list<br>
<a href="mailto:almighty-public@redhat.com" target="_blank">almighty-public@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/almighty-public" rel="noreferrer" target="_blank">https://www.redhat.com/mailman<wbr>/listinfo/almighty-public</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>