You've already forked go-semantic-release
test(internal/releaser/util): add test for CreateBearerHTTPClient and GetAccessToken
This commit is contained in:
43
internal/releaser/util/util_test.go
Normal file
43
internal/releaser/util/util_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user