MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestJSONErrorCodeUsesCodedErrors

Function TestJSONErrorCodeUsesCodedErrors

cmd/output_test.go:973–1028  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

971}
972
973func TestJSONErrorCodeUsesCodedErrors(t *testing.T) {
974 tests := []struct {
975 name string
976 err error
977 want string
978 }{
979 {
980 name: "path conflict",
981 err: pathConflictErrorWithPath("/file", "path exists and is not a folder: /file"),
982 want: jsonErrorCodePathConflict,
983 },
984 {
985 name: "optional argument validation",
986 err: invalidArgumentsErrorWithDetails("`account` accepts an optional `id` argument", argumentErrorDetails("id")),
987 want: jsonErrorCodeInvalidArguments,
988 },
989 {
990 name: "required argument validation",
991 err: invalidArgumentsErrorWithDetails("`add-member` requires `email`, `first`, and `last` arguments", argumentsErrorDetails("email", "first", "last")),
992 want: jsonErrorCodeInvalidArguments,
993 },
994 {
995 name: "auth required",
996 err: authRequiredErrorf("no saved Dropbox credentials"),
997 want: jsonErrorCodeAuthRequired,
998 },
999 {
1000 name: "app key required",
1001 err: appKeyRequiredError("Dropbox app key is required"),
1002 want: jsonErrorCodeAppKeyRequired,
1003 },
1004 {
1005 name: "auth exchange failed",
1006 err: authExchangeFailedError("authorization did not return an access token"),
1007 want: jsonErrorCodeAuthExchangeFailed,
1008 },
1009 {
1010 name: "auth refresh failed",
1011 err: authRefreshFailedErrorf("refresh saved Dropbox credentials: failed"),
1012 want: jsonErrorCodeAuthRefreshFailed,
1013 },
1014 {
1015 name: "partial transfer",
1016 err: partialStdoutError(12),
1017 want: jsonErrorCodePartialTransfer,
1018 },
1019 }
1020
1021 for _, tt := range tests {
1022 t.Run(tt.name, func(t *testing.T) {
1023 if got := jsonErrorCode(tt.err); got != tt.want {
1024 t.Fatalf("jsonErrorCode = %q, want %q", got, tt.want)
1025 }
1026 })
1027 }
1028}
1029
1030func TestExitCodeForStableJSONErrorCodes(t *testing.T) {

Callers

nothing calls this directly

Calls 10

argumentErrorDetailsFunction · 0.85
argumentsErrorDetailsFunction · 0.85
authRequiredErrorfFunction · 0.85
appKeyRequiredErrorFunction · 0.85
authExchangeFailedErrorFunction · 0.85
authRefreshFailedErrorfFunction · 0.85
partialStdoutErrorFunction · 0.85
jsonErrorCodeFunction · 0.85

Tested by

no test coverage detected