Skip to content

Commit

Permalink
ci: run tests on push (#100)
Browse files Browse the repository at this point in the history
* test: adjust expected values for event payloads to account for differences in float precision
  • Loading branch information
andrewjl-mux authored Dec 5, 2023
1 parent f29629d commit 98252fd
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 17 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Run Tests

on:
push:

jobs:
unit-tests:
name: Run Unit Tests
runs-on: macos-13
steps:
- name: Install xcbeautify
run: brew install xcbeautify
- name: Checkout
uses: actions/checkout@v3
- name: Run Tests
run: "scripts/run-unit-tests.sh MuxUploadSDK"
78 changes: 61 additions & 17 deletions Tests/MuxUploadSDKTests/Upload Tests/ReporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import XCTest

class ReporterTests: XCTestCase {

enum ExpectedJSONStrings {
/// There was a change in JSONEncoder behavior between
/// iOS 16 and 17 that affected precision when encoding
/// floats. It's immaterial in terms of data but does
/// require slightly different expected values when
/// testing.
enum ExpectedJSONStringsiOS16AndBelow {
static let inputStandardizationFailed = #"{"data":{"app_name":"AcmeApp","app_version":"3.2.1","device_model":"iPad","error_description":"foo","input_duration":3.1400000000000001,"input_size":1500000,"maximum_resolution":"default","non_standard_input_reasons":[],"platform_name":"iPadOS","platform_version":"15.0.0","sdk_version":"0.4.1","standardization_end_time":"2023-07-07T03:43:58Z","standardization_start_time":"2023-07-07T03:38:58Z","upload_canceled":false,"upload_url":"https:\/\/www.example.com"},"session_id":"xyz789","type":"upload_input_standardization_failed","version":"1"}"#

static let inputStandardizationSucceeded = #"{"data":{"app_name":"AcmeApp","app_version":"3.2.1","device_model":"iPad","input_duration":3.1400000000000001,"input_size":1500000,"maximum_resolution":"default","non_standard_input_reasons":[],"platform_name":"iPadOS","platform_version":"15.0.0","sdk_version":"0.4.1","standardization_end_time":"2023-07-07T03:43:58Z","standardization_start_time":"2023-07-07T03:38:58Z","upload_url":"https:\/\/www.example.com"},"session_id":"jkl567","type":"upload_input_standardization_succeeded","version":"1"}"#
Expand All @@ -19,6 +24,16 @@ class ReporterTests: XCTestCase {
static let uploadSucceeded = #"{"data":{"app_name":"AcmeApp","app_version":"3.2.1","device_model":"iPad","input_duration":3.1400000000000001,"input_size":1500000,"input_standardization_requested":true,"platform_name":"iPadOS","platform_version":"16.2.0","region_code":"US","sdk_version":"0.3.0","upload_end_time":"2023-07-07T04:12:48Z","upload_start_time":"2023-07-07T04:12:18Z","upload_url":"https:\/\/www.example.com"},"session_id":"abc123","type":"upload_succeeded","version":"1"}"#
}

enum ExpectedJSONStringsiOS17 {
static let inputStandardizationFailed = #"{"data":{"app_name":"AcmeApp","app_version":"3.2.1","device_model":"iPad","error_description":"foo","input_duration":3.14,"input_size":1500000,"maximum_resolution":"default","non_standard_input_reasons":[],"platform_name":"iPadOS","platform_version":"15.0.0","sdk_version":"0.4.1","standardization_end_time":"2023-07-07T03:43:58Z","standardization_start_time":"2023-07-07T03:38:58Z","upload_canceled":false,"upload_url":"https:\/\/www.example.com"},"session_id":"xyz789","type":"upload_input_standardization_failed","version":"1"}"#

static let inputStandardizationSucceeded = #"{"data":{"app_name":"AcmeApp","app_version":"3.2.1","device_model":"iPad","input_duration":3.14,"input_size":1500000,"maximum_resolution":"default","non_standard_input_reasons":[],"platform_name":"iPadOS","platform_version":"15.0.0","sdk_version":"0.4.1","standardization_end_time":"2023-07-07T03:43:58Z","standardization_start_time":"2023-07-07T03:38:58Z","upload_url":"https:\/\/www.example.com"},"session_id":"jkl567","type":"upload_input_standardization_succeeded","version":"1"}"#

static let uploadFailed = #"{"data":{"app_name":"AcmeApp","app_version":"3.2.1","device_model":"iPad","error_description":"foo","input_duration":3.14,"input_size":1500000,"input_standardization_requested":false,"platform_name":"iPadOS","platform_version":"16.2.0","region_code":"US","sdk_version":"0.3.0","upload_end_time":"2023-07-07T04:12:48Z","upload_start_time":"2023-07-07T04:12:18Z","upload_url":"https:\/\/www.example.com"},"session_id":"abc123","type":"upload_failed","version":"1"}"#

static let uploadSucceeded = #"{"data":{"app_name":"AcmeApp","app_version":"3.2.1","device_model":"iPad","input_duration":3.14,"input_size":1500000,"input_standardization_requested":true,"platform_name":"iPadOS","platform_version":"16.2.0","region_code":"US","sdk_version":"0.3.0","upload_end_time":"2023-07-07T04:12:48Z","upload_start_time":"2023-07-07T04:12:18Z","upload_url":"https:\/\/www.example.com"},"session_id":"abc123","type":"upload_succeeded","version":"1"}"#
}

var jsonEncoder = Reporter().jsonEncoder

func testInputStandardizationFailedEventSerialization() throws {
Expand Down Expand Up @@ -52,10 +67,18 @@ class ReporterTests: XCTestCase {
)
)

XCTAssertEqual(
json,
ExpectedJSONStrings.inputStandardizationFailed
)
if #available(iOS 17, *) {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS17.inputStandardizationFailed
)
} else {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS16AndBelow.inputStandardizationFailed
)
}

}

func testInputStandardizationSucceededEventSerialization() throws {
Expand Down Expand Up @@ -87,10 +110,17 @@ class ReporterTests: XCTestCase {
)
)

XCTAssertEqual(
json,
ExpectedJSONStrings.inputStandardizationSucceeded
)
if #available(iOS 17, *) {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS17.inputStandardizationSucceeded
)
} else {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS16AndBelow.inputStandardizationSucceeded
)
}
}

func testUploadFailedEventSerialization() throws {
Expand Down Expand Up @@ -123,10 +153,17 @@ class ReporterTests: XCTestCase {
)
)

XCTAssertEqual(
json,
ExpectedJSONStrings.uploadFailed
)
if #available(iOS 17, *) {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS17.uploadFailed
)
} else {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS16AndBelow.uploadFailed
)
}
}

func testUploadSucceededEventSerialization() throws {
Expand Down Expand Up @@ -159,10 +196,17 @@ class ReporterTests: XCTestCase {
)
)

XCTAssertEqual(
json,
ExpectedJSONStrings.uploadSucceeded
)
if #available(iOS 17, *) {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS17.uploadSucceeded
)
} else {
XCTAssertEqual(
json,
ExpectedJSONStringsiOS16AndBelow.uploadSucceeded
)
}
}

}
44 changes: 44 additions & 0 deletions scripts/run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)

set -euo pipefail

if [ $# -ne 1 ]; then
echo "▸ Usage: $0 SCHEME"
exit 1
fi

readonly SCHEME="$1"

if ! command -v xcbeautify &> /dev/null
then
echo -e "\033[1;31m ERROR: xcbeautify could not be found please install it... \033[0m"
exit 1
fi

echo "▸ Selecting Xcode 15"

sudo xcode-select -s /Applications/Xcode_15.0.app/Contents/Developer

echo "▸ Using Xcode Version: ${XCODE}"

echo "▸ Available Xcode SDKs"

xcodebuild -showsdks

echo "▸ Resolve Package Dependencies"

xcodebuild -resolvePackageDependencies

echo "▸ Available Schemes"

xcodebuild -list -json

echo "▸ Test ${SCHEME}"

xcodebuild clean test \
-scheme $SCHEME \
-destination 'platform=iOS Simulator,OS=17.0.1,name=iPhone 15' \
-sdk iphonesimulator17.0 \
| xcbeautify

0 comments on commit 98252fd

Please sign in to comment.