(t *testing.T)
| 971 | } |
| 972 | |
| 973 | func 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 | |
| 1030 | func TestExitCodeForStableJSONErrorCodes(t *testing.T) { |
nothing calls this directly
no test coverage detected