test(internal/releaser/util): add test for CreateBearerHTTPClient and GetAccessToken

This commit is contained in:
fwiedmann
2019-07-22 00:48:13 +02:00
parent 7b4db67cb7
commit 7d68d5835f
2 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package util_test
import (
"context"
"fmt"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
)
func TestCreateBearerHTTPClient(t *testing.T) {
client := util.CreateBearerHTTPClient(context.Background(), "")
assert.True(t, client != nil, "Client is empty")
}
type testDoubleToken struct {
providerName, token string
valid bool
}
var testDoubles = []testDoubleToken{
testDoubleToken{providerName: "test0", token: "foo", valid: true},
testDoubleToken{providerName: "test1", token: "", valid: false},
}
func TestGetAccessToken(t *testing.T) {
for _, testObject := range testDoubles {
envName := fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(testObject.providerName))
if err := os.Setenv(envName, testObject.token); err != nil {
fmt.Println(err.Error())
}
_, err := util.GetAccessToken(testObject.providerName)
assert.Equal(t, testObject.valid, err == nil)
os.Unsetenv(envName)
}
}