github.com/jchengjr77/canaveral@v1.0.1-0.20200715160102-ea9245d1a2fb/gh/ghcredhandler_test.go (about)

     1  package github
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/jchengjr77/canaveral/lib"
     8  )
     9  
    10  func TestAddGHCredsHandler(t *testing.T) {
    11  	err := os.Setenv("CredentialsTest", "true")
    12  	lib.Check(err)
    13  	// Github credentials shouldn't exist
    14  	if ghCredsExist() {
    15  		t.Error("Github credentials exist on entry into test (bad state)")
    16  	}
    17  
    18  	// Testing failure with no username
    19  	resNoUsr := lib.CaptureOutput(
    20  		func() {
    21  			addGHCredsHandler("", "password")
    22  		})
    23  	if resNoUsr != "A github username is required. Please provide one.\n" {
    24  		t.Logf("addGHCredsHandler('', _) output: %s\n", resNoUsr)
    25  		t.Error("func addGHCredsHandler() failed in case of ('', _)\n")
    26  	}
    27  
    28  	// Testing failure with no password
    29  	resNoPass := lib.CaptureOutput(
    30  		func() {
    31  			addGHCredsHandler("username", "")
    32  		})
    33  	if resNoPass != "A github personal auth token is required. Please provide one.\n" {
    34  		t.Logf("addGHCredsHandler('', _) output: %s\n", resNoPass)
    35  		t.Error("func addGHCredsHandler() failed in case of (_, '')\n")
    36  	}
    37  }