FSTDatastoreTests.mm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/Remote/FSTDatastore.h"
  17. #import <FirebaseFirestore/FIRFirestoreErrors.h>
  18. #import <GRPCClient/GRPCCall.h>
  19. #import <XCTest/XCTest.h>
  20. @interface FSTDatastoreTests : XCTestCase
  21. @end
  22. @implementation FSTDatastoreTests
  23. - (void)testIsPermanentWriteError {
  24. // From GRPCCall -cancel
  25. NSError *error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  26. code:FIRFirestoreErrorCodeCancelled
  27. userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}];
  28. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  29. // From GRPCCall -startNextRead
  30. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  31. code:FIRFirestoreErrorCodeResourceExhausted
  32. userInfo:@{
  33. NSLocalizedDescriptionKey :
  34. @"Client does not have enough memory to hold the server response."
  35. }];
  36. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  37. // From GRPCCall -startWithWriteable
  38. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  39. code:FIRFirestoreErrorCodeUnavailable
  40. userInfo:@{NSLocalizedDescriptionKey : @"Connectivity lost."}];
  41. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  42. // User info doesn't matter:
  43. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  44. code:FIRFirestoreErrorCodeUnavailable
  45. userInfo:nil];
  46. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  47. // "unauthenticated" is considered a recoverable error due to expired token.
  48. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  49. code:FIRFirestoreErrorCodeUnauthenticated
  50. userInfo:nil];
  51. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  52. }
  53. @end