From cb9fdea89853745d8069e84c807e7569afcc6992 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Mon, 13 Nov 2023 16:47:10 +0200 Subject: [PATCH] Add SauceLabs tests to CI (#137) * feat: add ci script * ci indent * sha * pathing * ios version fix * remove useless ls * pathing * add test script * pass sl creds to tests * generic build * remove device from destination * simulator sdk * show sdks * try any iphone device * use file ids * debug * debug * debug * better steps variables * reduce the amount of tests * add automation name * webdriver test * try accessibility identifiers * attempt finding by name * print page source * network tests * better test runner * more tests * update sl script * lint * add more ios versions * remove unused code * relax ios versions * update sl options * only upload to sl once * check out code * add minimum deployment target for test app * dont specify sdk version * change minimum deployment version * ios compatibility fixes * make the app work on ios 13 * add ios 13 to ci * try matching accessibility identifier * try different accessibility identifier * find element by accessibility id instead * find by ids, remove ios 13 * add alamofire test * use click not tap * remove debug lines from ci * use newer splunkrum api * name desired caps explicitly * upgrade to selenium 4 options * use safari options * use pinned appium client * use older appium api --- .github/workflows/ci.yml | 56 +++ .../project.pbxproj | 461 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../SauceLabsTestApp/AlamofireTests.swift | 54 ++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 63 +++ .../Assets.xcassets/Contents.json | 6 + .../SauceLabsTestApp/ContentView.swift | 129 +++++ .../SauceLabsTestApp/CustomSpanTest.swift | 41 ++ .../SauceLabsTestApp/LifecycleTests.swift | 58 +++ .../Preview Assets.xcassets/Contents.json | 6 + .../SauceLabsTestApp.entitlements | 10 + .../SauceLabsTestAppApp.swift | 127 +++++ .../SauceLabsTestApp/TestCase.swift | 77 +++ .../SauceLabsTestApp/UITests.swift | 41 ++ .../SauceLabsTestApp/URLSessionTests.swift | 173 +++++++ .../SauceLabsTestApp/Utils.swift | 37 ++ .../SauceLabsTestApp/sl_tests.py | 46 ++ .../contents.xcworkspacedata | 3 + .../xcshareddata/swiftpm/Package.resolved | 9 + 21 files changed, 1423 insertions(+) create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.pbxproj create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/AlamofireTests.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/Contents.json create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/ContentView.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/CustomSpanTest.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/LifecycleTests.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestApp.entitlements create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestAppApp.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/TestCase.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/UITests.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/URLSessionTests.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Utils.swift create mode 100644 SplunkRumWorkspace/SauceLabsTestApp/sl_tests.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8aad3af2..3379b1b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,62 @@ jobs: with: name: SplunkOtel.xcframework path: ./SplunkRumWorkspace/SplunkRum/xcframeworks/SplunkOtel.xcframework + saucelabs-prepare: + runs-on: macOS-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + - name: Build for Sauce Labs + run: | + BUILD_FOLDER="work/splunk-otel-ios/splunk-otel-ios/SauceLabsTests" + BUILD_PATH="Build/Products/Debug-iphonesimulator" + xcodebuild -showsdks + + xcodebuild -workspace SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace \ + -scheme SauceLabsTestApp \ + -configuration Debug \ + -sdk iphonesimulator \ + -derivedDataPath SauceLabsTests + zip ${GITHUB_WORKSPACE}/SauceLabsTestApp.zip $(find ~/$BUILD_FOLDER/$BUILD_PATH/SauceLabsTestApp.app -type f) + - name: Upload test app to Sauce Labs + id: sl-upload + run: | + cd /Users/runner/work/splunk-otel-ios/splunk-otel-ios/ + item_id=$(curl -u "${{secrets.SAUCELABS_USER}}:${{secrets.SAUCELABS_KEY}}" --location \ + --request POST 'https://api.us-west-1.saucelabs.com/v1/storage/upload' \ + --form 'payload=@"SauceLabsTestApp.zip"' \ + --form 'name="SauceLabsTestApp.zip"' \ + --form 'description="'"$GITHUB_SHA"'"' | jq -r .item.id) + echo "sl_file_id=$item_id" >> $GITHUB_OUTPUT + outputs: + sl_file_id: ${{ steps.sl-upload.outputs.sl_file_id }} + saucelabs-tests: + runs-on: macOS-latest + needs: saucelabs-prepare + strategy: + fail-fast: false + matrix: + os: ['14', '15', '16'] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + - name: Run Sauce Labs test cases + working-directory: SplunkRumWorkspace + env: + SAUCELABS_USER: ${{ secrets.SAUCELABS_USER }} + SAUCELABS_KEY: ${{ secrets.SAUCELABS_KEY }} + run: | + cd SauceLabsTestApp/ + python3 -m pip install Appium-Python-Client==2.11.1 + python3 sl_tests.py ${{ matrix.os }} ${{ needs.saucelabs-prepare.outputs.sl_file_id }} check_links: runs-on: ubuntu-22.04 steps: diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.pbxproj b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.pbxproj new file mode 100644 index 00000000..026f4159 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.pbxproj @@ -0,0 +1,461 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + E2098D6A29F9BE3D00F19A62 /* SplunkOtel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2098D6629F9BE2400F19A62 /* SplunkOtel.framework */; }; + E2098D6B29F9BE3D00F19A62 /* SplunkOtel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E2098D6629F9BE2400F19A62 /* SplunkOtel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + E2098D6F29F9CBBD00F19A62 /* Swifter in Frameworks */ = {isa = PBXBuildFile; productRef = E2098D6E29F9CBBD00F19A62 /* Swifter */; }; + E2098D712A1F98EB00F19A62 /* TestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2098D702A1F98EB00F19A62 /* TestCase.swift */; }; + E2098D732A1F993600F19A62 /* URLSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2098D722A1F993600F19A62 /* URLSessionTests.swift */; }; + E2098D752A25485000F19A62 /* LifecycleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2098D742A25485000F19A62 /* LifecycleTests.swift */; }; + E2098D772A25487F00F19A62 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2098D762A25487F00F19A62 /* Utils.swift */; }; + E2098D792A2548DC00F19A62 /* CustomSpanTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2098D782A2548DC00F19A62 /* CustomSpanTest.swift */; }; + E2098D7B2A25510100F19A62 /* UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2098D7A2A25510000F19A62 /* UITests.swift */; }; + E2098D7E2A26038500F19A62 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = E2098D7D2A26038500F19A62 /* Alamofire */; }; + E2098D802A2603AA00F19A62 /* AlamofireTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2098D7F2A2603AA00F19A62 /* AlamofireTests.swift */; }; + E26323D329E822450077E2A4 /* SauceLabsTestAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26323D229E822450077E2A4 /* SauceLabsTestAppApp.swift */; }; + E26323D529E822450077E2A4 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26323D429E822450077E2A4 /* ContentView.swift */; }; + E26323D729E822480077E2A4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E26323D629E822480077E2A4 /* Assets.xcassets */; }; + E26323DB29E822480077E2A4 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E26323DA29E822480077E2A4 /* Preview Assets.xcassets */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + E2098D6C29F9BE3D00F19A62 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + E2098D6B29F9BE3D00F19A62 /* SplunkOtel.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + E2098D6629F9BE2400F19A62 /* SplunkOtel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SplunkOtel.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + E2098D702A1F98EB00F19A62 /* TestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestCase.swift; sourceTree = ""; }; + E2098D722A1F993600F19A62 /* URLSessionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTests.swift; sourceTree = ""; }; + E2098D742A25485000F19A62 /* LifecycleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifecycleTests.swift; sourceTree = ""; }; + E2098D762A25487F00F19A62 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; + E2098D782A2548DC00F19A62 /* CustomSpanTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSpanTest.swift; sourceTree = ""; }; + E2098D7A2A25510000F19A62 /* UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITests.swift; sourceTree = ""; }; + E2098D7F2A2603AA00F19A62 /* AlamofireTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireTests.swift; sourceTree = ""; }; + E26323CF29E822450077E2A4 /* SauceLabsTestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SauceLabsTestApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; + E26323D229E822450077E2A4 /* SauceLabsTestAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SauceLabsTestAppApp.swift; sourceTree = ""; }; + E26323D429E822450077E2A4 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + E26323D629E822480077E2A4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + E26323D829E822480077E2A4 /* SauceLabsTestApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SauceLabsTestApp.entitlements; sourceTree = ""; }; + E26323DA29E822480077E2A4 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E26323CC29E822450077E2A4 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + E2098D7E2A26038500F19A62 /* Alamofire in Frameworks */, + E2098D6A29F9BE3D00F19A62 /* SplunkOtel.framework in Frameworks */, + E2098D6F29F9CBBD00F19A62 /* Swifter in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E2098D6529F9BE2400F19A62 /* Frameworks */ = { + isa = PBXGroup; + children = ( + E2098D6629F9BE2400F19A62 /* SplunkOtel.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + E26323C629E822450077E2A4 = { + isa = PBXGroup; + children = ( + E26323D129E822450077E2A4 /* SauceLabsTestApp */, + E26323D029E822450077E2A4 /* Products */, + E2098D6529F9BE2400F19A62 /* Frameworks */, + ); + sourceTree = ""; + }; + E26323D029E822450077E2A4 /* Products */ = { + isa = PBXGroup; + children = ( + E26323CF29E822450077E2A4 /* SauceLabsTestApp.app */, + ); + name = Products; + sourceTree = ""; + }; + E26323D129E822450077E2A4 /* SauceLabsTestApp */ = { + isa = PBXGroup; + children = ( + E26323D229E822450077E2A4 /* SauceLabsTestAppApp.swift */, + E26323D429E822450077E2A4 /* ContentView.swift */, + E26323D629E822480077E2A4 /* Assets.xcassets */, + E26323D829E822480077E2A4 /* SauceLabsTestApp.entitlements */, + E26323D929E822480077E2A4 /* Preview Content */, + E2098D702A1F98EB00F19A62 /* TestCase.swift */, + E2098D722A1F993600F19A62 /* URLSessionTests.swift */, + E2098D742A25485000F19A62 /* LifecycleTests.swift */, + E2098D762A25487F00F19A62 /* Utils.swift */, + E2098D782A2548DC00F19A62 /* CustomSpanTest.swift */, + E2098D7A2A25510000F19A62 /* UITests.swift */, + E2098D7F2A2603AA00F19A62 /* AlamofireTests.swift */, + ); + path = SauceLabsTestApp; + sourceTree = ""; + }; + E26323D929E822480077E2A4 /* Preview Content */ = { + isa = PBXGroup; + children = ( + E26323DA29E822480077E2A4 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E26323CE29E822450077E2A4 /* SauceLabsTestApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = E26323DE29E822480077E2A4 /* Build configuration list for PBXNativeTarget "SauceLabsTestApp" */; + buildPhases = ( + E26323CB29E822450077E2A4 /* Sources */, + E26323CC29E822450077E2A4 /* Frameworks */, + E26323CD29E822450077E2A4 /* Resources */, + E2098D6C29F9BE3D00F19A62 /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SauceLabsTestApp; + packageProductDependencies = ( + E2098D6E29F9CBBD00F19A62 /* Swifter */, + E2098D7D2A26038500F19A62 /* Alamofire */, + ); + productName = SauceLabsTestApp; + productReference = E26323CF29E822450077E2A4 /* SauceLabsTestApp.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E26323C729E822450077E2A4 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1420; + LastUpgradeCheck = 1420; + TargetAttributes = { + E26323CE29E822450077E2A4 = { + CreatedOnToolsVersion = 14.2; + }; + }; + }; + buildConfigurationList = E26323CA29E822450077E2A4 /* Build configuration list for PBXProject "SauceLabsTestApp" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = E26323C629E822450077E2A4; + packageReferences = ( + E2098D6D29F9CBBD00F19A62 /* XCRemoteSwiftPackageReference "swifter" */, + E2098D7C2A26038500F19A62 /* XCRemoteSwiftPackageReference "Alamofire" */, + ); + productRefGroup = E26323D029E822450077E2A4 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E26323CE29E822450077E2A4 /* SauceLabsTestApp */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + E26323CD29E822450077E2A4 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E26323DB29E822480077E2A4 /* Preview Assets.xcassets in Resources */, + E26323D729E822480077E2A4 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + E26323CB29E822450077E2A4 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E26323D529E822450077E2A4 /* ContentView.swift in Sources */, + E2098D7B2A25510100F19A62 /* UITests.swift in Sources */, + E26323D329E822450077E2A4 /* SauceLabsTestAppApp.swift in Sources */, + E2098D752A25485000F19A62 /* LifecycleTests.swift in Sources */, + E2098D792A2548DC00F19A62 /* CustomSpanTest.swift in Sources */, + E2098D732A1F993600F19A62 /* URLSessionTests.swift in Sources */, + E2098D712A1F98EB00F19A62 /* TestCase.swift in Sources */, + E2098D772A25487F00F19A62 /* Utils.swift in Sources */, + E2098D802A2603AA00F19A62 /* AlamofireTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + E26323DC29E822480077E2A4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + E26323DD29E822480077E2A4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + E26323DF29E822480077E2A4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = SauceLabsTestApp/SauceLabsTestApp.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SauceLabsTestApp/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13.1; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.splunk.SauceLabsTestApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + E26323E029E822480077E2A4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = SauceLabsTestApp/SauceLabsTestApp.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SauceLabsTestApp/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13.1; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.splunk.SauceLabsTestApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E26323CA29E822450077E2A4 /* Build configuration list for PBXProject "SauceLabsTestApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E26323DC29E822480077E2A4 /* Debug */, + E26323DD29E822480077E2A4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E26323DE29E822480077E2A4 /* Build configuration list for PBXNativeTarget "SauceLabsTestApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E26323DF29E822480077E2A4 /* Debug */, + E26323E029E822480077E2A4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + E2098D6D29F9CBBD00F19A62 /* XCRemoteSwiftPackageReference "swifter" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/httpswift/swifter"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.5.0; + }; + }; + E2098D7C2A26038500F19A62 /* XCRemoteSwiftPackageReference "Alamofire" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Alamofire/Alamofire.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.6.4; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + E2098D6E29F9CBBD00F19A62 /* Swifter */ = { + isa = XCSwiftPackageProductDependency; + package = E2098D6D29F9CBBD00F19A62 /* XCRemoteSwiftPackageReference "swifter" */; + productName = Swifter; + }; + E2098D7D2A26038500F19A62 /* Alamofire */ = { + isa = XCSwiftPackageProductDependency; + package = E2098D7C2A26038500F19A62 /* XCRemoteSwiftPackageReference "Alamofire" */; + productName = Alamofire; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = E26323C729E822450077E2A4 /* Project object */; +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/AlamofireTests.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/AlamofireTests.swift new file mode 100644 index 00000000..943aa4e0 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/AlamofireTests.swift @@ -0,0 +1,54 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation +import Alamofire + +class AlamofireRequestTest: TestCase { + init() { + super.init(name: "Alamofire.request") + } + + override func execute() { + AF.request(receiverEndpoint("/")).response { response in + if response.error != nil { + return self.fail() + } + + if let data = response.data { + if String(decoding: data, as: UTF8.self) != "hello" { + return self.fail() + } + } else { + self.fail() + } + } + } + + override func verify(_ span: TestZipkinSpan) { + if !matchesTest(span) { + return + } + + if span.name != "HTTP GET" { + return + } + + if !validNetworkSpan(span: span) { + return self.fail() + } + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AccentColor.colorset/Contents.json b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..532cd729 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,63 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/Contents.json b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/ContentView.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/ContentView.swift new file mode 100644 index 00000000..e95c69a5 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/ContentView.swift @@ -0,0 +1,129 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import SwiftUI +import SplunkOtel + +enum TestStatus: CustomStringConvertible { + case not_running, running, failure, timeout, success + + var description: String { + switch self { + case .running: return "running" + case .failure: return "failure" + case .success: return "success" + case .timeout: return "timeout" + default: return "not yet running" + } + } +} + +struct TestLabel: View { + var text = "" + var status: TestStatus + + var body: some View { + HStack { + Text(self.text).frame(maxWidth: .infinity, alignment: .leading).font(.system(size: 12)) + Text(self.status.description).font(.system(size: 12)) + } + .padding(4.0) + } +} + +var testsTracker = TestsTracker() + +typealias TestFunction = (_ fail: @escaping () -> Void) -> Void + +class TestsTracker: ObservableObject { + @Published var testCases: [String: TestStatus] = [:] + @Published var combinedStatus: TestStatus = .running + + func register(test: TestCase) { + self.testCases[test.name] = test.status + } + + func update(test: TestCase) { + self.testCases[test.name] = test.status + + if combinedStatus == .running { + if test.status == .failure || test.status == .timeout { + combinedStatus = .failure + return + } + + if testCases.values.allSatisfy({ $0 == .success }) { + combinedStatus = .success + } + } + } +} + +struct TestResultsView: View { + @ObservedObject private var tests = testsTracker + + var body: some View { + VStack { + VStack { + ForEach(tests.testCases.keys.sorted(), id: \.self) { test in + TestLabel(text: test, status: tests.testCases[test] ?? .not_running) + } + } + Spacer() + Text(self.tests.combinedStatus.description) + .accessibility(identifier: "test_result") + .background(labelColor()) + }.onAppear { + ViewControllerShowTest().run() + } + } + + func labelColor() -> Color { + switch tests.combinedStatus { + case .running: return .yellow + case .failure: return .red + case .success: return .green + default: return .white + } + } +} + +struct ContentView: View { + var body: some View { + NavigationView { + NavigationLink(destination: TestResultsView()) { + Text("results") + .accessibility(identifier: "results") + } + } + .onAppear { + let tests = [ + AppStartTest(), + AlamofireRequestTest(), + SplunkRumInitializeTest(), + CustomSpanTest(), + DataTaskTest(), + DataTaskWithCompletionHandlerTest(), + DownloadTaskTest(), + UploadTaskTest() + ] + + for test in tests { + test.run() + } + } + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/CustomSpanTest.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/CustomSpanTest.swift new file mode 100644 index 00000000..1e973636 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/CustomSpanTest.swift @@ -0,0 +1,41 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation +import SplunkOtel + +class CustomSpanTest: TestCase { + init() { + super.init(name: "customSpan") + } + + override func execute() { + let tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "customSpanTest", instrumentationVersion: nil) + let span = tracer.spanBuilder(spanName: "customSpan").startSpan() + span.setAttribute(key: "foo", value: "123") + span.end() + } + + override func verify(_ span: TestZipkinSpan) { + if span.name != "customSpan" { + return + } + + if span.tags["foo"] != "123" { + return self.fail() + } + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/LifecycleTests.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/LifecycleTests.swift new file mode 100644 index 00000000..0169cee5 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/LifecycleTests.swift @@ -0,0 +1,58 @@ +// +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation + +class AppStartTest: TestCase { + init() { + super.init(name: "appStart") + } + + override func verify(_ span: TestZipkinSpan) { + if span.name != "AppStart" { + return + } + + if span.tags["component"] != "appstart" { + return self.fail() + } + + if span.tags["app"] != "SauceLabsTestApp" { + return self.fail() + } + } +} + +class SplunkRumInitializeTest: TestCase { + init() { + super.init(name: "initialize") + } + + override func verify(_ span: TestZipkinSpan) { + if span.name != "SplunkRum.initialize" { + return + } + + if span.tags["component"] != "appstart" { + return self.fail() + } + + if span.tags["app"] != "SauceLabsTestApp" { + return self.fail() + } + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Preview Content/Preview Assets.xcassets/Contents.json b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestApp.entitlements b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestApp.entitlements new file mode 100644 index 00000000..f2ef3ae0 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestApp.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestAppApp.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestAppApp.swift new file mode 100644 index 00000000..194eb02b --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/SauceLabsTestAppApp.swift @@ -0,0 +1,127 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import SwiftUI +import SplunkOtel +import Swifter + +var receivedSpans: [TestZipkinSpan] = [] + +struct TestZipkinSpan: Decodable { + var name: String + var tags: [String: String] +} + +typealias SpanCallback = (TestZipkinSpan) -> Void + +class PublishedState: ObservableObject { + var listeners: [SpanCallback] = [] + + func receiveSpans(spans: [TestZipkinSpan]) { + DispatchQueue.main.async { + for listener in self.listeners { + for span in spans { + listener(span) + } + } + } + } + + func onSpan(_ on: @escaping SpanCallback) { + self.listeners.append(on) + } +} + +var globalState = PublishedState() +let receiverUrl = "http://127.0.0.1:8989" + +func receiverEndpoint(_ route: String) -> String { + return "\(receiverUrl)\(route)" +} + +@main +struct SauceLabsTestApp { + static func main() { + let server = HttpServer() + + server["/v1/traces"] = { request in + let spans = try! JSONDecoder().decode([TestZipkinSpan].self, from: Data(request.body)) + receivedSpans.append(contentsOf: spans) + globalState.receiveSpans(spans: spans) + return HttpResponse.ok(.text("ok")) + } + + server["/upload"] = { request in + let body = String(decoding: Data(request.body), as: UTF8.self) + return HttpResponse.ok(.text(body)) + } + + server["/"] = { _ in + return HttpResponse.ok(.text("hello")) + } + + try! server.start(8989) + + SplunkRumBuilder.init( + beaconUrl: receiverEndpoint("/v1/traces"), + rumAuth: "FAKE_RUM_AUTH" + ) + .allowInsecureBeacon(enabled: true) + .debug(enabled: true) + .globalAttributes(globalAttributes: [:]) + .build() + + if #available(iOS 14.0, *) { + TestApp.main() + } else { + UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self)) + } + } +} + +@available(iOS 14.0, *) +struct TestApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} + +class AppDelegate: NSObject, UIApplicationDelegate { + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + let config = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) + config.delegateClass = SceneDelegate.self + return config + } +} + +class SceneDelegate: NSObject, UIWindowSceneDelegate { + var window: UIWindow? + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + if #unavailable(iOS 14.0) { + let contentView = ContentView() + + if let windowScene = scene as? UIWindowScene { + let window = UIWindow(windowScene: windowScene) + window.rootViewController = UIHostingController(rootView: contentView) + window.makeKeyAndVisible() + self.window = window + } + } + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/TestCase.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/TestCase.swift new file mode 100644 index 00000000..83e61ac2 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/TestCase.swift @@ -0,0 +1,77 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation +import SplunkOtel + +class TestCase { + let name: String + var status: TestStatus = .not_running + var timeoutHandler: DispatchWorkItem? + + init(name: String) { + self.name = name + self.timeoutHandler = DispatchWorkItem(block: { + self.timeout() + }) + + globalState.onSpan { span in + self.verify(span) + if self.status == .running { + self.success() + } + } + testsTracker.register(test: self) + } + + func run() { + DispatchQueue.main.asyncAfter(deadline: .now() + 10, execute: self.timeoutHandler!) + self.status = .running + testsTracker.update(test: self) + + SplunkRum.setGlobalAttributes(["testname": self.name]) + self.execute() + SplunkRum.removeGlobalAttribute("testname") + } + + func execute() { + } + + func verify(_ span: TestZipkinSpan) { + } + + func end(_ status: TestStatus) { + self.timeoutHandler?.cancel() + self.status = status + testsTracker.update(test: self) + } + + func fail() { + self.end(.failure) + } + + func timeout() { + self.end(.timeout) + } + + func success() { + self.end(.success) + } + + func matchesTest(_ span: TestZipkinSpan) -> Bool { + return span.tags["testname"] == self.name + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/UITests.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/UITests.swift new file mode 100644 index 00000000..7d0dc900 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/UITests.swift @@ -0,0 +1,41 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation + +class ViewControllerShowTest: TestCase { + init() { + super.init(name: "showVC") + } + + override func verify(_ span: TestZipkinSpan) { + if span.name != "ShowVC" { + return + } + + if span.tags["component"] != "ui" { + return self.fail() + } + + if span.tags["last.screen.name"] == nil { + return self.fail() + } + + if span.tags["object.type"] == nil { + return self.fail() + } + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/URLSessionTests.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/URLSessionTests.swift new file mode 100644 index 00000000..42144065 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/URLSessionTests.swift @@ -0,0 +1,173 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation + +class DataTaskWithCompletionHandlerTest: TestCase { + init() { + super.init(name: "URLSession.dataTaskWithCompletionHandler") + } + + override func execute() { + let url = URL(string: receiverEndpoint("/"))! + + let task = URLSession.shared.dataTask(with: url) { (data, _, error) in + if error != nil { + return self.fail() + } + if let data = data { + if String(decoding: data, as: UTF8.self) != "hello" { + return self.fail() + } + } else { + self.fail() + } + } + + task.resume() + } + + override func verify(_ span: TestZipkinSpan) { + if !matchesTest(span) { + return + } + + if span.name != "HTTP GET" { + return + } + + if !validNetworkSpan(span: span) { + return self.fail() + } + } +} + +class DataTaskTest: TestCase { + init() { + super.init(name: "URLSession.dataTask") + } + + override func execute() { + let url = URL(string: receiverEndpoint("/"))! + let task = URLSession.shared.dataTask(with: url) { data, _, error in + if error != nil { + return self.fail() + } + if let data = data { + if String(decoding: data, as: UTF8.self) != "hello" { + return self.fail() + } + } else { + self.fail() + } + } + task.resume() + } + + override func verify(_ span: TestZipkinSpan) { + if !matchesTest(span) { + return + } + + if span.name != "HTTP GET" { + return + } + + if !validNetworkSpan(span: span) { + return self.fail() + } + } +} + +class UploadTaskTest: TestCase { + init() { + super.init(name: "URLSession.uploadTask") + } + + override func execute() { + let url = URL(string: receiverEndpoint("/upload"))! + var request = URLRequest(url: url) + request.httpMethod = "POST" + + let uploadData = Data("foobar".utf8) + let task = URLSession.shared.uploadTask(with: request, from: uploadData) { data, _, error in + if error != nil { + return self.fail() + } + + if let data = data { + if String(decoding: data, as: UTF8.self) != "foobar" { + return self.fail() + } + } else { + self.fail() + } + } + task.resume() + } + + override func verify(_ span: TestZipkinSpan) { + if !matchesTest(span) { + return + } + + if span.name != "HTTP POST" { + return + } + } +} + +class DownloadTaskTest: TestCase { + init() { + super.init(name: "URLSession.downloadTask") + } + + override func execute() { + let url = URL(string: receiverEndpoint("/"))! + let task = URLSession.shared.downloadTask(with: url) { path, _, error in + if error != nil { + self.fail() + } + + if let path = path { + if let content = try? String(contentsOf: path) { + if content != "hello" { + self.fail() + } + } else { + self.fail() + } + } else { + self.fail() + } + } + task.resume() + } + + override func verify(_ span: TestZipkinSpan) { + if !matchesTest(span) { + return + } + + if span.name != "HTTP GET" { + return + } + + if !validNetworkSpan(span: span) { + return self.fail() + } + } +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Utils.swift b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Utils.swift new file mode 100644 index 00000000..c7de984f --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/SauceLabsTestApp/Utils.swift @@ -0,0 +1,37 @@ +/* +Copyright 2023 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation + +func validNetworkSpan(span: TestZipkinSpan) -> Bool { + if span.tags["http.url"] != receiverEndpoint("/") { + return false + } + + if span.tags["http.method"] != "GET" { + return false + } + + if span.tags["http.status_code"] != "200" { + return false + } + + if span.tags["component"] != "http" { + return false + } + + return true +} diff --git a/SplunkRumWorkspace/SauceLabsTestApp/sl_tests.py b/SplunkRumWorkspace/SauceLabsTestApp/sl_tests.py new file mode 100644 index 00000000..70930fd9 --- /dev/null +++ b/SplunkRumWorkspace/SauceLabsTestApp/sl_tests.py @@ -0,0 +1,46 @@ +import unittest +import os +from appium import webdriver +from datetime import datetime +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import sys + +class IOSTests(unittest.TestCase): + + def setUp(self): + currentTime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + caps = {} + + sl_file_id = sys.argv[2] + + caps['platformName'] = 'iOS' + caps['appium:app'] = f'storage:{sl_file_id}' + caps['appium:deviceName'] = 'iPhone Simulator' + caps['appium:platformVersion'] = sys.argv[1] + caps['appium:automationName'] = 'XCUITest' + caps['sauce:options'] = {} + caps['sauce:options']['name'] = 'SplunkRum tests' + currentTime + caps['sauce:options']['accessKey'] = os.environ['SAUCELABS_KEY'] + caps['sauce:options']['username'] = os.environ['SAUCELABS_USER'] + url = f'https://ondemand.us-west-1.saucelabs.com:443/wd/hub' + self.driver=webdriver.Remote(url, caps) + + + def tearDown(self): + self.driver.quit() + + def test_spans(self): + self.driver.find_element(By.ID, "results").click() + WebDriverWait(self.driver, 20).until( + EC.text_to_be_present_in_element((By.ID, "test_result"), "success") + ) + +if __name__ == "__main__": + suite = unittest.TestLoader().loadTestsFromTestCase(IOSTests) + testRunner_result = unittest.TextTestRunner(verbosity=2).run(suite) + if testRunner_result.wasSuccessful(): + exit(0) + else: + exit(1) diff --git a/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/contents.xcworkspacedata b/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/contents.xcworkspacedata index a1f662ba..a1b1644e 100644 --- a/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/contents.xcworkspacedata +++ b/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/xcshareddata/swiftpm/Package.resolved b/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9f494a96..fff5905c 100644 --- a/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/SplunkRumWorkspace/SplunkRumWorkspace.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,14 @@ { "pins" : [ + { + "identity" : "alamofire", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Alamofire/Alamofire.git", + "state" : { + "revision" : "bc268c28fb170f494de9e9927c371b8342979ece", + "version" : "5.7.1" + } + }, { "identity" : "swifter", "kind" : "remoteSourceControl",