Tests for CLI (#6)
* Completed List cmd and added API calls * Minor comments and add delete code to pass linting * Typo in descriptions * Minor comments * Validations * Validations-1 * improved branch flag validation * removed build * working after refactory with bad names * Command working, test not working * Corrected creation of service * Finalized structure using service * Deleted tests * cleanup * cleanup * cleanup * removed space with tab * aligned types in model.go * Update model.go * resolved comments * Refactor * removed long descriptions * Working incomplete tests * Completed tests * cleanup * checks * PR comments * PR comments * minor comment issue * minor comment issue * updated tests to work with workflow * Updated tests to support new option service * Improved eror handling for list * Improved error handling * Upgraded go-gh * reusing rest client error
This commit is contained in:
16
internal/test_utils.go
Normal file
16
internal/test_utils.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/h2non/gock.v1"
|
||||
)
|
||||
|
||||
func PrintPendingMocks(mocks []gock.Mock) string {
|
||||
paths := []string{}
|
||||
for _, mock := range mocks {
|
||||
paths = append(paths, mock.Request().URLStruct.String())
|
||||
}
|
||||
return fmt.Sprintf("%d unmatched mocks: %s", len(paths), strings.Join(paths, ", "))
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func FormatCacheSize(size_in_bytes float64) string {
|
||||
func PrettyPrintCacheList(caches []types.ActionsCache) {
|
||||
fd := os.Stdout.Fd()
|
||||
ws, _ := term.GetWinsize(fd)
|
||||
width := math.Min(float64(ws.Width), 180)
|
||||
width := math.Max(math.Min(float64(ws.Width), 180), 100)
|
||||
|
||||
sizeWidth := SIZE_COLUMN_WIDTH // hard-coded size as the content is scoped
|
||||
timeWidth := LAST_ACCESSED_AT_COLUMN_WIDTH // hard-coded size as the content is scoped
|
||||
@@ -90,7 +90,7 @@ func getFormattedCacheInfo(cache types.ActionsCache, keyWidth int, sizeWidth int
|
||||
size := trimOrPad(fmt.Sprintf("[%s]", FormatCacheSize(cache.SizeInBytes)), sizeWidth)
|
||||
ref := trimOrPad(cache.Ref, refWidth)
|
||||
time := trimOrPad(lastAccessedTime(cache.LastAccessedAt), timeWidth)
|
||||
return fmt.Sprintf(" %s %s %s %s", key, size, ref, time)
|
||||
return fmt.Sprintf("%s %s %s %s", key, size, ref, time)
|
||||
}
|
||||
|
||||
func RedTick() string {
|
||||
|
||||
55
internal/utils_test.go
Normal file
55
internal/utils_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetRepo_IncorrectRepoString(t *testing.T) {
|
||||
r := "testOrg/testRepo/123/123"
|
||||
repo, err := GetRepo(r)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, repo)
|
||||
assert.Equal(t, err.Error(), fmt.Sprintf("expected the \"[HOST/]OWNER/REPO\" format, got \"%s\"", r))
|
||||
}
|
||||
|
||||
func TestGetRepo_CorrectRepoString(t *testing.T) {
|
||||
r := "testOrg/testRepo"
|
||||
repo, err := GetRepo(r)
|
||||
|
||||
assert.NotNil(t, repo)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, repo.Host(), "github.com")
|
||||
assert.Equal(t, repo.Owner(), "testOrg")
|
||||
assert.Equal(t, repo.Name(), "testRepo")
|
||||
}
|
||||
|
||||
func TestGetRepo_CorrectRepoStringWithCustomHost(t *testing.T) {
|
||||
r := "api.testEnterprise.com/testOrg/testRepo"
|
||||
repo, err := GetRepo(r)
|
||||
|
||||
assert.NotNil(t, repo)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, repo.Host(), "api.testEnterprise.com")
|
||||
assert.Equal(t, repo.Owner(), "testOrg")
|
||||
assert.Equal(t, repo.Name(), "testRepo")
|
||||
}
|
||||
|
||||
func TestFormatCacheSize_MB(t *testing.T) {
|
||||
cacheSizeInBytes := 1024 * 1024 * 1.5
|
||||
cacheSizeDetailString := FormatCacheSize(cacheSizeInBytes)
|
||||
|
||||
assert.NotNil(t, cacheSizeDetailString)
|
||||
assert.Equal(t, cacheSizeDetailString, "1.50 MB")
|
||||
}
|
||||
|
||||
func TestFormatCacheSize_GB(t *testing.T) {
|
||||
cacheSizeInBytes := 1024 * 1024 * 1024 * 1.5
|
||||
cacheSizeDetailString := FormatCacheSize(cacheSizeInBytes)
|
||||
|
||||
assert.NotNil(t, cacheSizeDetailString)
|
||||
assert.Equal(t, cacheSizeDetailString, "1.50 GB")
|
||||
}
|
||||
Reference in New Issue
Block a user