Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit-test github action #7

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.yaml]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- @aws-amplify/amplify-ios

/.github/CODEOWNERS @aws-amplify/amplify-ios-admins
50 changes: 50 additions & 0 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Unit Test

on:
pull_request:

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
unit-test:
name: "[${{ matrix.os }}] Unit Test"
environment: Unit Test # TODO(5d): remove this line after repo is marked as public
strategy:
fail-fast: false
matrix:
include:
- scheme: AWSAppSyncApolloExtensions
os: iOS
sdk: iphonesimulator
destination: platform=iOS Simulator,name=iPhone 15,OS=latest
- scheme: AWSAppSyncApolloExtensions
os: macOS
sdk: macosx
destination: platform=OS X,arch=x86_64
- scheme: AWSAppSyncApolloExtensions
os: watchOS
sdk: watchsimulator
destination: platform=watchOS Simulator,name=Apple Watch Series 9 (45mm),OS=latest
- scheme: AWSAppSyncApolloExtensions
os: tvOS
sdk: appletvsimulator
destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest

runs-on: macos-14
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false
token: ${{ secrets.PAT }} # TODO(5d): remove this line after repo is marked as public

- name: ${{ matrix.os }}
run: |
xcodebuild test \
-scheme ${{ matrix.scheme }} \
-destination "${{ matrix.destination }}" \
-sdk ${{ matrix.sdk }} \
-only-testing:"${{ matrix.scheme }}Tests" | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
/.build
build/
/Packages
xcuserdata/
DerivedData/
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class LocalWebSocketServer {

func sendTransientFailureToConnections() {
self.connections.forEach {
var metadata = NWProtocolWebSocket.Metadata(opcode: .close)
let metadata = NWProtocolWebSocket.Metadata(opcode: .close)
metadata.closeCode = .protocolCode(NWProtocolWebSocket.CloseCode.Defined.internalServerError)
$0.send(
content: nil,
Expand Down