2022-07-14 02:14:03 +05:30
|
|
|
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)
|
|
|
|
|
|
2023-03-11 17:49:00 +01:00
|
|
|
assert.ErrorContains(t, err, fmt.Sprintf("expected the \"[HOST/]OWNER/REPO\" format, got \"%s\"", r))
|
2022-07-14 02:14:03 +05:30
|
|
|
assert.Nil(t, repo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetRepo_CorrectRepoString(t *testing.T) {
|
|
|
|
|
r := "testOrg/testRepo"
|
|
|
|
|
repo, err := GetRepo(r)
|
|
|
|
|
|
2023-03-11 17:49:00 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
if assert.NotNil(t, repo) {
|
|
|
|
|
assert.Equal(t, "github.com", repo.Host())
|
|
|
|
|
assert.Equal(t, "testOrg", repo.Owner())
|
|
|
|
|
assert.Equal(t, "testRepo", repo.Name())
|
|
|
|
|
}
|
2022-07-14 02:14:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetRepo_CorrectRepoStringWithCustomHost(t *testing.T) {
|
|
|
|
|
r := "api.testEnterprise.com/testOrg/testRepo"
|
|
|
|
|
repo, err := GetRepo(r)
|
|
|
|
|
|
2023-03-11 17:49:00 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
if assert.NotNil(t, repo) {
|
|
|
|
|
assert.Equal(t, "api.testEnterprise.com", repo.Host())
|
|
|
|
|
assert.Equal(t, "testOrg", repo.Owner())
|
|
|
|
|
assert.Equal(t, "testRepo", repo.Name())
|
|
|
|
|
}
|
2022-07-14 02:14:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFormatCacheSize_MB(t *testing.T) {
|
|
|
|
|
cacheSizeInBytes := 1024 * 1024 * 1.5
|
|
|
|
|
cacheSizeDetailString := FormatCacheSize(cacheSizeInBytes)
|
|
|
|
|
|
2023-03-11 17:49:00 +01:00
|
|
|
assert.Equal(t, "1.50 MB", cacheSizeDetailString)
|
2022-07-14 02:14:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFormatCacheSize_GB(t *testing.T) {
|
|
|
|
|
cacheSizeInBytes := 1024 * 1024 * 1024 * 1.5
|
|
|
|
|
cacheSizeDetailString := FormatCacheSize(cacheSizeInBytes)
|
|
|
|
|
|
2023-03-11 17:49:00 +01:00
|
|
|
assert.Equal(t, "1.50 GB", cacheSizeDetailString)
|
2022-07-18 14:51:28 +05:30
|
|
|
}
|