FSTDatastoreTests.mm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 =
  31. [NSError errorWithDomain:FIRFirestoreErrorDomain
  32. code:FIRFirestoreErrorCodeResourceExhausted
  33. userInfo:@{
  34. NSLocalizedDescriptionKey :
  35. @"Client does not have enough memory to hold the server response."
  36. }];
  37. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  38. // From GRPCCall -startWithWriteable
  39. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  40. code:FIRFirestoreErrorCodeUnavailable
  41. userInfo:@{NSLocalizedDescriptionKey : @"Connectivity lost."}];
  42. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  43. // User info doesn't matter:
  44. error = [NSError errorWithDomain:FIRFirestoreErrorDomain
  45. code:FIRFirestoreErrorCodeUnavailable
  46. userInfo:nil];
  47. XCTAssertFalse([FSTDatastore isPermanentWriteError:error]);
  48. }
  49. @end