Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d88f49218f | ||
|
|
281c73efa0 | ||
|
|
c16b05447b | ||
|
|
a9d75d16fb | ||
|
|
71fc548b2d | ||
|
|
24022671c7 | ||
|
|
88a1bc276b | ||
|
|
27d4a4c8f5 | ||
|
|
ed34fad2e5 | ||
|
|
bf7745edd0 | ||
|
|
47113d1159 | ||
|
|
9adb9e80c2 | ||
|
|
18233abdce | ||
|
|
d3293b69e1 | ||
|
|
2b273da8da | ||
|
|
235994ccc5 | ||
|
|
ccd695dfaa | ||
|
|
b8890ddb4c | ||
|
|
c196049591 | ||
|
|
1aec73ad5e | ||
|
|
ebd16ae99c |
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -9,7 +9,7 @@ assignees: ''
|
||||
|
||||
### Describe the bug
|
||||
|
||||
A clear and concise description of what the bug is. Include CLI version by typing `gh actions-cache --version` and extension version by typing `gh actions-cache --version`. <!--TODO: Implement version printing for the cache -->
|
||||
A clear and concise description of what the bug is. Include CLI version by typing `gh --version` and the extension version `gh extensions list | grep actions-cache`.
|
||||
|
||||
### Steps to reproduce the behavior
|
||||
|
||||
|
||||
67
.github/workflows/canary.yaml
vendored
Normal file
67
.github/workflows/canary.yaml
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
name: Canary Test
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [released]
|
||||
schedule:
|
||||
- cron: "30 18 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
|
||||
jobs:
|
||||
upload:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
name: cache upload (${{ matrix.os }})
|
||||
steps:
|
||||
- name: Create file to cache
|
||||
run: |
|
||||
mkdir test-cache
|
||||
echo "foo" > test-cache/test.txt
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: test-cache
|
||||
key: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
canary:
|
||||
needs: upload
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
CacheKey: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v3
|
||||
- name: Install extension
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh extensions install actions/gh-actions-cache
|
||||
- name: List Command
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
cache_found=$(gh actions-cache list --key $CacheKey --limit 100 --branch $GITHUB_REF --order desc --sort created-at | grep $CacheKey)
|
||||
echo $cache_found
|
||||
[[ -z "$cache_found" ]] && exit 1 || echo "Cache List Successful"
|
||||
- name: Delete Command
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
cache_delete=$(gh actions-cache delete $CacheKey --branch $GITHUB_REF --confirm | grep "Deleted 1 cache entry with key")
|
||||
echo $cache_delete
|
||||
[[ -z "$cache_delete" ]] && exit 1 || echo "Cache Delete Successful"
|
||||
- name: Slack Notification on failure
|
||||
if: failure()
|
||||
uses: 8398a7/action-slack@a74b761b4089b5d730d813fbedcd2ec5d394f3af
|
||||
with:
|
||||
text: actions/gh-actions-cache canary failure
|
||||
status: ${{ job.status }}
|
||||
fields: repo,workflow,message,author,action,ref
|
||||
env:
|
||||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
86
.github/workflows/e2e_test.yml
vendored
Normal file
86
.github/workflows/e2e_test.yml
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
name: E2E Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
|
||||
jobs:
|
||||
upload:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
name: cache upload (${{ matrix.os }})
|
||||
steps:
|
||||
- name: Create file to cache
|
||||
run: |
|
||||
mkdir test-cache
|
||||
echo "foo" > test-cache/test.txt
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: test-cache
|
||||
key: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
canary:
|
||||
needs: upload
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
CacheKey: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v3
|
||||
- name: Restore Go modules cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: go-${{ runner.os }}-${{ hashFiles('go.mod') }}
|
||||
restore-keys: |
|
||||
go-${{ runner.os }}-
|
||||
- name: Build the project
|
||||
env:
|
||||
CGO_ENABLED: 0
|
||||
run: go build
|
||||
- name: Install extension
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
|
||||
run: gh extensions install .
|
||||
- name: Print help
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
|
||||
run: |
|
||||
gh actions-cache --help
|
||||
- name: List Command
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
|
||||
run: |
|
||||
cache_found=$(gh actions-cache list --key $CacheKey --limit 100 --branch $GITHUB_REF --order desc --sort created-at | grep $CacheKey)
|
||||
echo $cache_found
|
||||
[[ -z "$cache_found" ]] && exit 1 || echo "Cache List Successful"
|
||||
- name: Delete Command
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
|
||||
run: |
|
||||
cache_delete=$(gh actions-cache delete $CacheKey --branch $GITHUB_REF --confirm | grep "Deleted 1 cache entry with key")
|
||||
echo $cache_delete
|
||||
[[ -z "$cache_delete" ]] && exit 1 || echo "Cache Delete Successful"
|
||||
- name: Slack Notification on failure
|
||||
if: failure()
|
||||
uses: 8398a7/action-slack@a74b761b4089b5d730d813fbedcd2ec5d394f3af
|
||||
with:
|
||||
text: actions/gh-actions-cache E2E test failure
|
||||
status: ${{ job.status }}
|
||||
fields: repo,workflow,message,author,action,ref
|
||||
env:
|
||||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.18
|
||||
- uses: actions/checkout@v3
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@@ -37,5 +37,7 @@ jobs:
|
||||
GH_TOKEN: dummy-token-to-facilitate-rest-client
|
||||
|
||||
- uses: cli/gh-extension-precompile@v1
|
||||
env:
|
||||
CGO_ENABLED: 0
|
||||
with:
|
||||
go_version: "1.18"
|
||||
go_version: "1.18"
|
||||
|
||||
25
README.md
25
README.md
@@ -8,11 +8,13 @@ It also allows deleting a corrupt, incomplete or dangling cache. A cache can be
|
||||
|
||||
This extension builds on top of [cache management](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#managing-caches) capabilities exposed by GitHub [APIs](https://docs.github.com/en/rest/actions/cache).
|
||||
|
||||
**Note:** This extension only supports github.com and GitHub Enterprise Server 3.7 & above.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Install the `gh` CLI - see the [installation](https://github.com/cli/cli#installation)
|
||||
|
||||
_Installation requires a minimum version (2.0.0) of the the GitHub CLI that supports extensions._
|
||||
_Installation requires a minimum version (2.0.0) of the GitHub CLI that supports extensions._
|
||||
|
||||
2. Install this extension:
|
||||
|
||||
@@ -95,6 +97,25 @@ EXAMPLES:
|
||||
|
||||
> ℹ️ There could be multiple caches in a repo with same key. This can happen when different caches with same key have been created for different branches. it may also happen if the `version` property of the cache is different which usually means that cache with same key was created for different OS or with different [paths](https://github.com/actions/cache#inputs).
|
||||
|
||||
## FAQs
|
||||
|
||||
### How the current repository is selected?
|
||||
|
||||
This extension currently uses the `go-gh` module's [`CurrentRepository` function](https://github.com/actions/gh-actions-cache/blob/d3293b69e1c5bc17686d815ab2c64618618c95df/internal/utils.go#L26) to determine the current repo. This function returns the first element of the list returned by the `git.Remotes()` internal function, which [sorts remotes such that `upstream` precedes `github`, which precedes `origin`](https://github.com/cli/go-gh/blob/c2fc965daac88a8a38dd8af02f236095b5dd48f1/internal/git/remote.go#L30). As such, if an `upstream` remote is present, this extension's default behavior is to return its caches.
|
||||
|
||||
User's input `--repo <owner>/<name>` will override any current git repository and extension will fetch caches for the same.
|
||||
|
||||
### How to remove trimming in results
|
||||
|
||||
We support a table printer that allows users to pipe output for further processing. If we want to list down certain columns without trimming then just selecting the column number in the below command will work.
|
||||
|
||||
`gh actions-cache list -R <owner>/<repo_name> | cut -f 1,2,3`
|
||||
|
||||
This will print columns 1,2 and 3 without any trimming.
|
||||
|
||||
### Delete all caches for a branch
|
||||
|
||||
Please refers to this doc - [Force deleting cache entries](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries)
|
||||
|
||||
## Contributing
|
||||
If anything feels off, or if you feel that some functionality is missing, please check out the [contributing page](CONTRIBUTING.md). There you will find instructions for sharing your feedback, building the tool locally, and submitting pull requests to the project.
|
||||
If anything feels off, or if you feel that some functionality is missing, please check out the [contributing page](CONTRIBUTING.md). There you will find instructions for sharing your feedback, building the tool locally, and submitting pull requests to the project.
|
||||
|
||||
@@ -62,8 +62,8 @@ func NewCmdDelete() *cobra.Command {
|
||||
}
|
||||
err = survey.AskOne(prompt, &choice)
|
||||
if err != nil {
|
||||
fmt.Println("Error occured while taking input from user while trying to delete cache")
|
||||
return types.HandledError{Message: "Error occured while taking input from user while trying to delete cache.", InnerError: err}
|
||||
fmt.Println("Error occurred while taking input from user while trying to delete cache")
|
||||
return types.HandledError{Message: "Error occurred while taking input from user while trying to delete cache.", InnerError: err}
|
||||
}
|
||||
|
||||
f.Confirm = choice == "Delete"
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/actions/gh-actions-cache/internal"
|
||||
@@ -19,8 +16,7 @@ func TestDeleteWithIncorrectArguments(t *testing.T) {
|
||||
cmd.SetArgs([]string{})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("accepts 1 arg(s), received 0"))
|
||||
assert.ErrorContains(t, err, "accepts 1 arg(s), received 0")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -31,8 +27,7 @@ func TestDeleteWithIncorrectRepo(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo/123/123", "cacheName"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("expected the \"[HOST/]OWNER/REPO\" format, got \"testOrg/testRepo/123/123\""))
|
||||
assert.ErrorContains(t, err, "expected the \"[HOST/]OWNER/REPO\" format, got \"testOrg/testRepo/123/123\"")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -52,11 +47,11 @@ func TestDeleteWithIncorrectRepoForDeleteCaches(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo", "cacheName"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
var customError types.HandledError
|
||||
errors.As(err, &customError)
|
||||
assert.Equal(t, customError.Message, "The given repo does not exist.")
|
||||
if assert.ErrorAs(t, err, &customError) {
|
||||
assert.Equal(t, "The given repo does not exist.", customError.Message)
|
||||
}
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
func TestDeleteSuccessWithConfirmFlagProvided(t *testing.T) {
|
||||
@@ -85,7 +80,7 @@ func TestDeleteSuccessWithConfirmFlagProvided(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo", "2022-06-29T13:33:49", "--confirm"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -116,7 +111,7 @@ func TestDeleteFailureWhileTakingUserInput(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo", "2022-06-29T13:33:49"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -135,13 +130,10 @@ func TestDeleteWithUnauthorizedRequestForDeleteCaches(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo", "cacheKey", "--confirm"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, reflect.TypeOf(err), reflect.TypeOf(types.HandledError{}))
|
||||
|
||||
var customError types.HandledError
|
||||
errors.As(err, &customError)
|
||||
assert.Equal(t, customError.Message, "Must have admin rights to Repository.")
|
||||
|
||||
if assert.ErrorAs(t, err, &customError) {
|
||||
assert.Equal(t, "Must have admin rights to Repository.", customError.Message)
|
||||
}
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -160,12 +152,9 @@ func TestDeleteWithInternalServerErrorForDeleteCaches(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo", "cacheKey", "--confirm"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, reflect.TypeOf(err), reflect.TypeOf(types.HandledError{}))
|
||||
|
||||
var customError types.HandledError
|
||||
errors.As(err, &customError)
|
||||
assert.Equal(t, customError.Message, "We could not process your request due to internal error.")
|
||||
|
||||
if assert.ErrorAs(t, err, &customError) {
|
||||
assert.Equal(t, "We could not process your request due to internal error.", customError.Message)
|
||||
}
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
15
cmd/list.go
15
cmd/list.go
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/actions/gh-actions-cache/service"
|
||||
"github.com/actions/gh-actions-cache/types"
|
||||
"github.com/spf13/cobra"
|
||||
ghTerm "github.com/cli/go-gh/pkg/term"
|
||||
)
|
||||
|
||||
func NewCmdList() *cobra.Command {
|
||||
@@ -41,9 +42,13 @@ func NewCmdList() *cobra.Command {
|
||||
return types.HandledError{Message: err.Error(), InnerError: err}
|
||||
}
|
||||
|
||||
// This will be used to determine the if output is terminal
|
||||
terminal := ghTerm.FromEnv()
|
||||
isTerminalOutput := terminal.IsTerminalOutput()
|
||||
|
||||
if f.Branch == "" && f.Key == "" {
|
||||
totalCacheSize, err := artifactCache.GetCacheUsage()
|
||||
if err == nil && totalCacheSize > 0 {
|
||||
if err == nil && totalCacheSize > 0 && isTerminalOutput {
|
||||
fmt.Printf("Total caches size %s\n\n", internal.FormatCacheSize(totalCacheSize))
|
||||
}
|
||||
}
|
||||
@@ -58,9 +63,11 @@ func NewCmdList() *cobra.Command {
|
||||
totalCaches := listCacheResponse.TotalCount
|
||||
caches := listCacheResponse.ActionsCaches
|
||||
if len(caches) > 0 {
|
||||
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
|
||||
if isTerminalOutput {
|
||||
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
|
||||
}
|
||||
internal.PrettyPrintCacheList(caches)
|
||||
} else {
|
||||
} else if isTerminalOutput {
|
||||
fmt.Printf("There are no Actions caches currently present in this repo or for the provided filters\n")
|
||||
}
|
||||
return nil
|
||||
@@ -69,7 +76,7 @@ func NewCmdList() *cobra.Command {
|
||||
|
||||
listCmd.Flags().StringVarP(&f.Repo, "repo", "R", "", "Select another repository for finding actions cache.")
|
||||
listCmd.Flags().StringVarP(&f.Branch, "branch", "B", "", "Filter by branch")
|
||||
listCmd.Flags().IntVarP(&f.Limit, "limit", "", 30, "Number of items to fetch between 1 and 100")
|
||||
listCmd.Flags().IntVarP(&f.Limit, "limit", "L", 30, "Number of items to fetch between 1 and 100")
|
||||
listCmd.Flags().StringVarP(&f.Key, "key", "", "", "Filter by key")
|
||||
listCmd.Flags().StringVarP(&f.Order, "order", "", "", "Order of caches returned (asc/desc)")
|
||||
listCmd.Flags().StringVarP(&f.Sort, "sort", "", "", "Sort fetched caches (last-used/size/created-at)")
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/actions/gh-actions-cache/internal"
|
||||
@@ -21,8 +17,7 @@ func TestListWithIncorrectArguments(t *testing.T) {
|
||||
cmd.SetArgs([]string{"keyValue"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("Invalid argument(s). Expected 0 received 1"))
|
||||
assert.ErrorContains(t, err, "Invalid argument(s). Expected 0 received 1")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -33,8 +28,7 @@ func TestListWithIncorrectRepo(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo/123/123"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("expected the \"[HOST/]OWNER/REPO\" format, got \"testOrg/testRepo/123/123\""))
|
||||
assert.ErrorContains(t, err, "expected the \"[HOST/]OWNER/REPO\" format, got \"testOrg/testRepo/123/123\"")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -45,8 +39,7 @@ func TestListWithNegativeLimit(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--limit", "-1", "--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("-1 is not a valid integer value for limit flag. Allowed values: 1-100"))
|
||||
assert.ErrorContains(t, err, "-1 is not a valid integer value for limit flag. Allowed values: 1-100")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -57,8 +50,18 @@ func TestListWithIncorrectLimit(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--limit", "101", "--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("101 is not a valid integer value for limit flag. Allowed values: 1-100"))
|
||||
assert.ErrorContains(t, err, "101 is not a valid integer value for limit flag. Allowed values: 1-100")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
func TestListLimitShorthandUsingIncorrectLimit(t *testing.T) {
|
||||
t.Cleanup(gock.Off)
|
||||
|
||||
cmd := NewCmdList()
|
||||
cmd.SetArgs([]string{"-L", "102", "--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.ErrorContains(t, err, "102 is not a valid integer value for limit flag. Allowed values: 1-100")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -69,8 +72,7 @@ func TestListWithIncorrectOrder(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--order", "incorrectOrderValue", "--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("incorrectOrderValue is not a valid value for order flag. Allowed values: asc/desc"))
|
||||
assert.ErrorContains(t, err, "incorrectOrderValue is not a valid value for order flag. Allowed values: asc/desc")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -81,8 +83,7 @@ func TestListWithIncorrectSort(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--sort", "incorrectSortValue", "--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("incorrectSortValue is not a valid value for sort flag. Allowed values: last-used/size/created-at"))
|
||||
assert.ErrorContains(t, err, "incorrectSortValue is not a valid value for sort flag. Allowed values: last-used/size/created-at")
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -109,13 +110,10 @@ func TestListWithIncorrectRepoForListCaches(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, reflect.TypeOf(err), reflect.TypeOf(types.HandledError{}))
|
||||
|
||||
var customError types.HandledError
|
||||
errors.As(err, &customError)
|
||||
assert.Equal(t, customError.Message, "The given repo does not exist.")
|
||||
|
||||
if assert.ErrorAs(t, err, &customError) {
|
||||
assert.Equal(t, "The given repo does not exist.", customError.Message)
|
||||
}
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -142,13 +140,10 @@ func TestListWithUnauthorizedRequestForListCaches(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, reflect.TypeOf(err), reflect.TypeOf(types.HandledError{}))
|
||||
|
||||
var customError types.HandledError
|
||||
errors.As(err, &customError)
|
||||
assert.Equal(t, customError.Message, "Must have admin rights to Repository.")
|
||||
|
||||
if assert.ErrorAs(t, err, &customError) {
|
||||
assert.Equal(t, "Must have admin rights to Repository.", customError.Message)
|
||||
}
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -175,13 +170,10 @@ func TestListWithInternalServerErrorForListCaches(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, reflect.TypeOf(err), reflect.TypeOf(types.HandledError{}))
|
||||
|
||||
var customError types.HandledError
|
||||
errors.As(err, &customError)
|
||||
assert.Equal(t, customError.Message, "We could not process your request due to internal error.")
|
||||
|
||||
if assert.ErrorAs(t, err, &customError) {
|
||||
assert.Equal(t, "We could not process your request due to internal error.", customError.Message)
|
||||
}
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -217,6 +209,6 @@ func TestListSuccess(t *testing.T) {
|
||||
cmd.SetArgs([]string{"--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const VERSION = "1.0.0"
|
||||
const VERSION = "1.0.1"
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "gh-actions-cache",
|
||||
|
||||
36
go.mod
36
go.mod
@@ -5,31 +5,41 @@ go 1.18
|
||||
require (
|
||||
github.com/AlecAivazis/survey/v2 v2.3.5
|
||||
github.com/TwiN/go-color v1.1.0
|
||||
github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4
|
||||
github.com/cli/go-gh v1.2.1
|
||||
github.com/nleeper/goment v1.4.4
|
||||
github.com/spf13/cobra v1.4.0
|
||||
github.com/spf13/cobra v1.5.0
|
||||
github.com/stretchr/testify v1.8.0
|
||||
)
|
||||
|
||||
require github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
require (
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/muesli/reflow v0.3.0 // indirect
|
||||
github.com/muesli/termenv v0.15.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cli/safeexec v1.0.0
|
||||
github.com/cli/shurcooL-graphql v0.0.1 // indirect
|
||||
github.com/cli/safeexec v1.0.1 // indirect
|
||||
github.com/cli/shurcooL-graphql v0.0.3 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
|
||||
github.com/henvic/httpretty v0.0.6 // indirect
|
||||
github.com/henvic/httpretty v0.1.2 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/mattn/go-colorable v0.1.2 // indirect
|
||||
github.com/mattn/go-isatty v0.0.8
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/tkuchiki/go-timezone v0.2.0 // indirect
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
|
||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
golang.org/x/net v0.11.0 // indirect
|
||||
golang.org/x/sys v0.9.0 // indirect
|
||||
golang.org/x/term v0.9.0 // indirect
|
||||
golang.org/x/text v0.10.0 // indirect
|
||||
gopkg.in/h2non/gock.v1 v1.1.2
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
98
go.sum
98
go.sum
@@ -1,18 +1,20 @@
|
||||
github.com/AlecAivazis/survey/v2 v2.3.5 h1:A8cYupsAZkjaUmhtTYv3sSqc7LO5mp1XDfqe5E/9wRQ=
|
||||
github.com/AlecAivazis/survey/v2 v2.3.5/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI=
|
||||
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
|
||||
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
|
||||
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
|
||||
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
|
||||
github.com/TwiN/go-color v1.1.0 h1:yhLAHgjp2iAxmNjDiVb6Z073NE65yoaPlcki1Q22yyQ=
|
||||
github.com/TwiN/go-color v1.1.0/go.mod h1:aKVf4e1mD4ai2FtPifkDPP5iyoCwiK08YGzGwerjKo0=
|
||||
github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4 h1:6WrekNBE2Y+Xl9OCl7vsg49SSN68hwaVryfEawQevaQ=
|
||||
github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4/go.mod h1:Y/QFb/VxnXQH0W4VlP+507HVxMzQ430x8kdjUuVcono=
|
||||
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
|
||||
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
|
||||
github.com/cli/shurcooL-graphql v0.0.1 h1:/9J3t9O6p1B8zdBBtQighq5g7DQRItBwuwGh3SocsKM=
|
||||
github.com/cli/shurcooL-graphql v0.0.1/go.mod h1:U7gCSuMZP/Qy7kbqkk5PrqXEeDgtfG5K+W+u8weorps=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/cli/go-gh v1.2.1 h1:xFrjejSsgPiwXFP6VYynKWwxLQcNJy3Twbu82ZDlR/o=
|
||||
github.com/cli/go-gh v1.2.1/go.mod h1:Jxk8X+TCO4Ui/GarwY9tByWm/8zp4jJktzVZNlTW5VM=
|
||||
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
|
||||
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
|
||||
github.com/cli/shurcooL-graphql v0.0.3 h1:CtpPxyGDs136/+ZeyAfUKYmcQBjDlq5aqnrDCW5Ghh8=
|
||||
github.com/cli/shurcooL-graphql v0.0.3/go.mod h1:tlrLmw/n5Q/+4qSvosT+9/W5zc8ZMjnJeYBxSdb4nWA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
|
||||
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -20,8 +22,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||
github.com/henvic/httpretty v0.0.6 h1:JdzGzKZBajBfnvlMALXXMVQWxWMF/ofTy8C3/OSUTxs=
|
||||
github.com/henvic/httpretty v0.0.6/go.mod h1:X38wLjWXHkXT7r2+uK8LjCMne9rsuNaBLJ+5cU2/Pmo=
|
||||
github.com/henvic/httpretty v0.1.2 h1:EQo556sO0xeXAjP10eB+BZARMuvkdGqtfeS4Ntjvkiw=
|
||||
github.com/henvic/httpretty v0.1.2/go.mod h1:ViEsly7wgdugYtymX54pYp6Vv2wqZmNHayJ6q8tlKCc=
|
||||
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
|
||||
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
@@ -29,53 +31,97 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
|
||||
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
|
||||
github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs=
|
||||
github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/nleeper/goment v1.4.4 h1:GlMTpxvhueljArSunzYjN9Ri4SOmpn0Vh2hg2z/IIl8=
|
||||
github.com/nleeper/goment v1.4.4/go.mod h1:zDl5bAyDhqxwQKAvkSXMRLOdCowrdZz53ofRJc4VhTo=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
|
||||
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
|
||||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
||||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e h1:BuzhfgfWQbX0dWzYzT1zsORLnHRv3bcRcsaUk0VmXA8=
|
||||
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI=
|
||||
github.com/tkuchiki/go-timezone v0.2.0 h1:yyZVHtQRVZ+wvlte5HXvSpBkR0dPYnPEIgq9qqAqltk=
|
||||
github.com/tkuchiki/go-timezone v0.2.0/go.mod h1:b1Ean9v2UXtxSq4TZF0i/TU9NuoWa9hOzOKoGCV2zqY=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
|
||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28=
|
||||
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
|
||||
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
|
||||
@@ -3,11 +3,6 @@ package internal
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/TwiN/go-color"
|
||||
@@ -15,16 +10,13 @@ import (
|
||||
gh "github.com/cli/go-gh"
|
||||
"github.com/cli/go-gh/pkg/api"
|
||||
ghRepo "github.com/cli/go-gh/pkg/repository"
|
||||
"github.com/cli/safeexec"
|
||||
"github.com/mattn/go-isatty"
|
||||
ghTableprinter "github.com/cli/go-gh/pkg/tableprinter"
|
||||
ghTerm "github.com/cli/go-gh/pkg/term"
|
||||
"github.com/nleeper/goment"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const MB_IN_BYTES = 1024 * 1024
|
||||
const GB_IN_BYTES = 1024 * 1024 * 1024
|
||||
const SIZE_COLUMN_WIDTH = 15
|
||||
const LAST_ACCESSED_AT_COLUMN_WIDTH = 20
|
||||
|
||||
func GetRepo(r string) (ghRepo.Repository, error) {
|
||||
if r != "" {
|
||||
@@ -51,17 +43,19 @@ func FormatCacheSize(size_in_bytes float64) string {
|
||||
}
|
||||
|
||||
func PrettyPrintCacheList(caches []types.ActionsCache) {
|
||||
width, _, _ := getTerminalWidth(os.Stdout)
|
||||
width = int(math.Max(float64(width), 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
|
||||
keyWidth := int(math.Floor(0.65 * float64(width-SIZE_COLUMN_WIDTH-LAST_ACCESSED_AT_COLUMN_WIDTH)))
|
||||
refWidth := int(math.Floor(0.20 * float64(width-SIZE_COLUMN_WIDTH-LAST_ACCESSED_AT_COLUMN_WIDTH)))
|
||||
terminal := ghTerm.FromEnv()
|
||||
w, _, _ := terminal.Size()
|
||||
tp := ghTableprinter.New(terminal.Out(), terminal.IsTerminalOutput(), w)
|
||||
|
||||
for _, cache := range caches {
|
||||
var formattedRow string = getFormattedCacheInfo(cache, keyWidth, sizeWidth, refWidth, timeWidth)
|
||||
fmt.Println(formattedRow)
|
||||
tp.AddField(cache.Key)
|
||||
tp.AddField(FormatCacheSize(cache.SizeInBytes))
|
||||
tp.AddField(cache.Ref)
|
||||
tp.AddField(lastAccessedTime(cache.LastAccessedAt))
|
||||
tp.EndRow()
|
||||
}
|
||||
|
||||
_ = tp.Render()
|
||||
}
|
||||
|
||||
func PrettyPrintTrimmedCacheList(caches []types.ActionsCache) {
|
||||
@@ -78,24 +72,7 @@ func PrettyPrintTrimmedCacheList(caches []types.ActionsCache) {
|
||||
|
||||
func lastAccessedTime(lastAccessedAt string) string {
|
||||
lastAccessed, _ := goment.New(lastAccessedAt)
|
||||
return fmt.Sprintf(" %s", lastAccessed.FromNow())
|
||||
}
|
||||
|
||||
func trimOrPad(value string, maxSize int) string {
|
||||
if len(value) > maxSize {
|
||||
value = value[:maxSize-3] + "..."
|
||||
} else {
|
||||
value = value + strings.Repeat(" ", maxSize-len(value))
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func getFormattedCacheInfo(cache types.ActionsCache, keyWidth int, sizeWidth int, refWidth int, timeWidth int) string {
|
||||
key := trimOrPad(cache.Key, keyWidth)
|
||||
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 lastAccessed.FromNow()
|
||||
}
|
||||
|
||||
func RedTick() string {
|
||||
@@ -112,24 +89,6 @@ func PrintSingularOrPlural(count int, singularStr string, pluralStr string) stri
|
||||
return fmt.Sprintf("%d %s", count, pluralStr)
|
||||
}
|
||||
|
||||
func getTerminalWidth(f *os.File) (int, int, error) {
|
||||
if !isatty.IsCygwinTerminal(f.Fd()) {
|
||||
return term.GetSize(int(f.Fd()))
|
||||
}
|
||||
tputExe, err := safeexec.LookPath("tput")
|
||||
if err != nil {
|
||||
return 100, 100, nil
|
||||
}
|
||||
tputCmd := exec.Command(tputExe, "cols")
|
||||
tputCmd.Stdin = os.Stdin
|
||||
if out, err := tputCmd.Output(); err == nil {
|
||||
if w, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil {
|
||||
return w, 100, nil
|
||||
}
|
||||
}
|
||||
return 100, 100, nil
|
||||
}
|
||||
|
||||
func HttpErrorHandler(err error, errMsg404 string) types.HandledError {
|
||||
var httpError api.HTTPError
|
||||
if errors.As(err, &httpError) && httpError.StatusCode == 404 {
|
||||
|
||||
@@ -11,45 +11,44 @@ func TestGetRepo_IncorrectRepoString(t *testing.T) {
|
||||
r := "testOrg/testRepo/123/123"
|
||||
repo, err := GetRepo(r)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.ErrorContains(t, err, fmt.Sprintf("expected the \"[HOST/]OWNER/REPO\" format, got \"%s\"", r))
|
||||
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")
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
assert.Equal(t, "1.50 MB", cacheSizeDetailString)
|
||||
}
|
||||
|
||||
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")
|
||||
assert.Equal(t, "1.50 GB", cacheSizeDetailString)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
@@ -9,6 +8,7 @@ import (
|
||||
"github.com/actions/gh-actions-cache/types"
|
||||
"github.com/cli/go-gh/pkg/api"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/h2non/gock.v1"
|
||||
)
|
||||
|
||||
@@ -27,14 +27,15 @@ func TestGetCacheUsage_CorrectRepo(t *testing.T) {
|
||||
}`)
|
||||
|
||||
repo, err := internal.GetRepo("testOrg/testRepo")
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
artifactCache, err := NewArtifactCache(repo, "list", VERSION)
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, artifactCache)
|
||||
totalCacheSize, err := artifactCache.GetCacheUsage()
|
||||
|
||||
assert.Equal(t, totalCacheSize, float64(291205))
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, float64(291205), totalCacheSize)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -50,18 +51,18 @@ func TestGetCacheUsage_IncorrectRepo(t *testing.T) {
|
||||
}`)
|
||||
|
||||
repo, err := internal.GetRepo("testOrg/wrongRepo")
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
artifactCache, err := NewArtifactCache(repo, "list", VERSION)
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, artifactCache)
|
||||
totalCacheSize, err := artifactCache.GetCacheUsage()
|
||||
var httpError api.HTTPError
|
||||
errors.As(err, &httpError)
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, httpError.StatusCode, 404)
|
||||
assert.Equal(t, httpError.Message, "Not Found")
|
||||
assert.Equal(t, totalCacheSize, float64(-1))
|
||||
if assert.ErrorAs(t, err, &httpError) {
|
||||
assert.Equal(t, 404, httpError.StatusCode)
|
||||
assert.Equal(t, "Not Found", httpError.Message)
|
||||
}
|
||||
assert.Equal(t, float64(-1), totalCacheSize)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -86,21 +87,23 @@ func TestListCaches_Success(t *testing.T) {
|
||||
}`)
|
||||
|
||||
repo, err := internal.GetRepo("testOrg/testRepo")
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := types.ListOptions{BaseOptions: types.BaseOptions{Repo: "testOrg/testRepo"}, Limit: 30}
|
||||
queryParams := url.Values{}
|
||||
f.GenerateQueryParams(queryParams)
|
||||
|
||||
artifactCache, err := NewArtifactCache(repo, "list", VERSION)
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, artifactCache)
|
||||
listCacheResponse, err := artifactCache.ListCaches(queryParams)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, listCacheResponse)
|
||||
assert.Equal(t, listCacheResponse.TotalCount, 1)
|
||||
assert.Equal(t, len(listCacheResponse.ActionsCaches), 1)
|
||||
assert.Equal(t, listCacheResponse.ActionsCaches[0].Id, 29)
|
||||
assert.NoError(t, err)
|
||||
if assert.NotNil(t, listCacheResponse) {
|
||||
assert.Equal(t, 1, listCacheResponse.TotalCount)
|
||||
assert.Equal(t, 1, len(listCacheResponse.ActionsCaches))
|
||||
assert.Equal(t, 29, listCacheResponse.ActionsCaches[0].Id)
|
||||
}
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -116,22 +119,22 @@ func TestListCaches_Failure(t *testing.T) {
|
||||
}`)
|
||||
|
||||
repo, err := internal.GetRepo("testOrg/testRepo")
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := types.ListOptions{BaseOptions: types.BaseOptions{Repo: "testOrg/testRepo"}, Limit: 30}
|
||||
queryParams := url.Values{}
|
||||
f.GenerateQueryParams(queryParams)
|
||||
|
||||
artifactCache, err := NewArtifactCache(repo, "list", VERSION)
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, artifactCache)
|
||||
listCacheResponse, err := artifactCache.ListCaches(queryParams)
|
||||
var httpError api.HTTPError
|
||||
errors.As(err, &httpError)
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, httpError.StatusCode, 404)
|
||||
assert.Equal(t, httpError.Message, "Not Found")
|
||||
assert.Equal(t, listCacheResponse, types.ListApiResponse{})
|
||||
if assert.ErrorAs(t, err, &httpError) {
|
||||
assert.Equal(t, 404, httpError.StatusCode)
|
||||
assert.Equal(t, "Not Found", httpError.Message)
|
||||
}
|
||||
assert.Equal(t, types.ListApiResponse{}, listCacheResponse)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -156,18 +159,19 @@ func TestDeleteCaches_Success(t *testing.T) {
|
||||
}`)
|
||||
|
||||
repo, err := internal.GetRepo("testOrg/testRepo")
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := types.DeleteOptions{BaseOptions: types.BaseOptions{Repo: "testOrg/testRepo"}}
|
||||
queryParams := url.Values{}
|
||||
f.GenerateBaseQueryParams(queryParams)
|
||||
|
||||
artifactCache, err := NewArtifactCache(repo, "delete", VERSION)
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, artifactCache)
|
||||
deletedCache, err := artifactCache.DeleteCaches(queryParams)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, deletedCache, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, deletedCache)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -183,17 +187,18 @@ func TestDeleteCaches_Failure(t *testing.T) {
|
||||
}`)
|
||||
|
||||
repo, err := internal.GetRepo("testOrg/testRepo")
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := types.DeleteOptions{BaseOptions: types.BaseOptions{Repo: "testOrg/testRepo"}}
|
||||
queryParams := url.Values{}
|
||||
f.GenerateBaseQueryParams(queryParams)
|
||||
|
||||
artifactCache, err := NewArtifactCache(repo, "delete", VERSION)
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, artifactCache)
|
||||
deletedCache, err := artifactCache.DeleteCaches(queryParams)
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, deletedCache, 0)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, 0, deletedCache)
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type HandledError struct {
|
||||
Message string
|
||||
InnerError error
|
||||
@@ -11,5 +7,5 @@ type HandledError struct {
|
||||
|
||||
// Allow HandledError to satisfy error interface.
|
||||
func (err HandledError) Error() string {
|
||||
return fmt.Sprintf(err.Message)
|
||||
return err.Message
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user