Skip to content

Commit

Permalink
update unit test case using regex for tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Aug 26, 2024
1 parent 344ecc7 commit e7127a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
jobs:
unit-test:
name: "[${{ matrix.os }}] Unit Test"
environment: Unit Test
environment: Unit Test # TODO(5d): remove this line after repo is marked as public
strategy:
fail-fast: false
matrix:
Expand All @@ -39,7 +39,7 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false
token: ${{ secrets.PAT }}
token: ${{ secrets.PAT }} # TODO(5d): remove this line after repo is marked as public

- name: ${{ matrix.os }}
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import XCTest

class PackageInfoTests: XCTestCase {

@available(iOS 16.0, *)
/// user agent header has format of:
/// UA/2.0 lang/swift/x.x(.x) os/[iOS, macOS, watchOS]/x.x(.x) lib/aws-appsync-apollo-extensions-swift/x.x.x
func testUserAgentHasCorrectFormat() async throws {
let format = try Regex(
"^UA/2\\.0 " +
let pattern = "^UA/2\\.0 " +
"lang/swift#\\d+\\.\\d+(?:\\.\\d+)? " +
"os/(?:iOS|macOS|watchOS)#\\d+\\.\\d+(?:\\.\\d+)? " +
"os/(?:iOS|macOS|watchOS|tvOS)#\\d+\\.\\d+(?:\\.\\d+)? " +
"lib/aws-appsync-apollo-extensions-swift#\\d+\\.\\d+\\.\\d+ " +
"md/apollo#\\d+\\.\\d+\\.\\d+$"
)
let regex = try NSRegularExpression(pattern: pattern)
let userAgent = await PackageInfo.userAgent
let matches = userAgent.ranges(of: format)
XCTAssertTrue(!matches.isEmpty)
let matches = regex.numberOfMatches(in: userAgent, options: [], range: NSRange(location: 0, length: userAgent.utf8.count))
XCTAssertTrue(matches > 0)
}
}

0 comments on commit e7127a1

Please sign in to comment.