Merge pull request #7502 from dokku/7454-consistent-report-exit-code
Ensure all report subcommands exit 0 when there is no app
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package appjson
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
@@ -9,6 +11,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -209,6 +209,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
@@ -9,6 +11,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -108,6 +108,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -336,7 +336,7 @@ func UnfilteredDokkuApps() ([]string, error) {
|
||||
dokkuRoot := MustGetEnv("DOKKU_ROOT")
|
||||
files, err := os.ReadDir(dokkuRoot)
|
||||
if err != nil {
|
||||
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
||||
return apps, NoAppsExist
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
@@ -351,7 +351,7 @@ func UnfilteredDokkuApps() ([]string, error) {
|
||||
}
|
||||
|
||||
if len(apps) == 0 {
|
||||
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
||||
return apps, NoAppsExist
|
||||
}
|
||||
|
||||
return apps, nil
|
||||
@@ -653,6 +653,11 @@ func (err *AppDoesNotExist) Error() string {
|
||||
return fmt.Sprintf("App %s does not exist", err.appName)
|
||||
}
|
||||
|
||||
// NoAppsExist wraps error to include the app name
|
||||
// and is used to distinguish between a normal error and an error
|
||||
// where the app is missing
|
||||
var NoAppsExist = errors.New("You haven't deployed any applications yet")
|
||||
|
||||
// VarArgs skips a number of incoming arguments, returning what is left over
|
||||
func VarArgs(arguments []string, skip int) []string {
|
||||
if len(arguments) <= skip {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@@ -33,7 +32,7 @@ func filterApps(apps []string) ([]string, error) {
|
||||
filteredApps = removeEmptyEntries(filteredApps)
|
||||
|
||||
if len(filteredApps) == 0 {
|
||||
return filteredApps, fmt.Errorf("You haven't deployed any applications yet")
|
||||
return filteredApps, NoAppsExist
|
||||
}
|
||||
|
||||
return filteredApps, nil
|
||||
|
||||
@@ -2,6 +2,7 @@ package cron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@@ -55,6 +56,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -52,6 +52,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -163,6 +163,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -135,6 +135,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -65,6 +65,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -44,6 +44,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -72,6 +72,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
@@ -28,6 +30,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -940,6 +941,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
@@ -9,6 +11,10 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
|
||||
@@ -4,17 +4,18 @@ load test_helper
|
||||
|
||||
setup() {
|
||||
global_setup
|
||||
deploy_app
|
||||
rm -f /tmp/fake-docker-bin
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -f /tmp/fake-docker-bin
|
||||
destroy_app
|
||||
destroy_app || true
|
||||
global_teardown
|
||||
}
|
||||
|
||||
@test "(report) report" {
|
||||
deploy_app
|
||||
|
||||
run /bin/bash -c "dokku report"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
@@ -57,6 +58,8 @@ teardown() {
|
||||
}
|
||||
|
||||
@test "(report) custom docker bin" {
|
||||
deploy_app
|
||||
|
||||
export DOCKER_BIN="docker"
|
||||
run /bin/bash -c "dokku report"
|
||||
echo "output: $output"
|
||||
@@ -85,3 +88,52 @@ teardown() {
|
||||
|
||||
unset DOCKER_BIN
|
||||
}
|
||||
|
||||
@test "(report) exit 0 when no apps exist" {
|
||||
run /bin/bash -c "dokku report"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
plugins=(
|
||||
app-json
|
||||
apps
|
||||
builder
|
||||
builder-dockerfile
|
||||
builder-herokuish
|
||||
builder-lambda
|
||||
builder-nixpacks
|
||||
builder-pack
|
||||
buildpacks
|
||||
caddy
|
||||
certs
|
||||
checks
|
||||
cron
|
||||
docker-options
|
||||
domains
|
||||
git
|
||||
haproxy
|
||||
logs
|
||||
network
|
||||
nginx
|
||||
openresty
|
||||
ports
|
||||
proxy
|
||||
ps
|
||||
registry
|
||||
resource
|
||||
scheduler
|
||||
scheduler-docker-local
|
||||
scheduler-k3s
|
||||
storage
|
||||
traefik
|
||||
)
|
||||
|
||||
for plugin in "${plugins[@]}"; do
|
||||
run /bin/bash -c "dokku $plugin:report 2>&1"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "You haven't deployed any applications yet"
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user