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: integration tests revamp #645

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
49 changes: 23 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES
- name: Update mtime for incremental builds
uses: chetan/git-restore-mtime-action@v2
- run: make dot-env
- name: Debug
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Debug PLATFORM="${{ matrix.platform }}" xcodebuild
- name: Release
Expand All @@ -62,7 +61,6 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: lcov.info


xcodebuild:
name: xcodebuild (15)
runs-on: macos-14
Expand Down Expand Up @@ -105,36 +103,35 @@ jobs:
run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES
- name: Update mtime for incremental builds
uses: chetan/git-restore-mtime-action@v2
- run: make dot-env
- name: Debug
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Debug PLATFORM="${{ matrix.platform }}" xcodebuild
- name: Release
if: matrix.skip_release != '1'
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Release PLATFORM="${{ matrix.platform }}" xcodebuild

# linux:
# name: linux
# strategy:
# matrix:
# swift-version: ["5.10"]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: swift-actions/setup-swift@v2
# with:
# swift-version: ${{ matrix.swift-version }}
# - name: Cache build
# uses: actions/cache@v3
# with:
# path: |
# .build
# key: |
# build-spm-linux-${{ matrix.swift-version }}-${{ hashFiles('**/Sources/**/*.swift', '**/Tests/**/*.swift', '**/Package.resolved') }}
# restore-keys: |
# build-spm-linux-${{ matrix.swift-version }}-
# - run: make dot-env
# - name: Run tests
# run: swift test --skip IntegrationTests
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: supabase/setup-cli@v1
- uses: actions/cache@v4
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- run: supabase start
working-directory: ./Tests/IntegrationTests
- name: Run tests
run: swift test
env:
SUPABASE_URL: http://localhost:54321
SUPABASE_ANON_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
SUPABASE_SERVICE_ROLE_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
- name: Stop infrastructure
if: always()
run: supabase stop
working-directory: ./Tests/IntegrationTests

# library-evolution:
# name: Library (evolution)
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/integration-tests.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows_disabled/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ jobs:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- run: make dot-env
- name: Run tests
run: swift test --filter AuthTests.
1 change: 0 additions & 1 deletion .github/workflows_disabled/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ jobs:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- run: make dot-env
- name: Run tests
run: swift test --filter FunctionsTests.
32 changes: 32 additions & 0 deletions .github/workflows_disabled/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Integration Tests

on:
push:
branches:
- main
- release/*
workflow_dispatch:

concurrency:
group: integration-tests-${{ github.ref }}
cancel-in-progress: true

jobs:
integration-tests:
runs-on: ubuntu-latest
name: Integration Tests
steps:
- uses: actions/checkout@v4
- uses: supabase/setup-cli@v1
- run: supabase start
working-directory: ./Tests/IntegrationTests
- name: Run tests
run: swift test --filter IntegrationTests
env:
SUPABASE_URL: http://localhost:54321
SUPABASE_ANON_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
SUPABASE_SERVICE_ROLE_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
- name: Stop infrastructure
if: always()
run: supabase stop
working-directory: ./Tests/IntegrationTests
1 change: 0 additions & 1 deletion .github/workflows_disabled/postgrest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ jobs:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- run: make dot-env
- name: Run tests
run: swift test --filter PostgRESTTests.
1 change: 0 additions & 1 deletion .github/workflows_disabled/realtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ jobs:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- run: make dot-env
- name: Run tests
run: swift test --filter RealtimeTests.
1 change: 0 additions & 1 deletion .github/workflows_disabled/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ jobs:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- run: make dot-env
- name: Run tests
run: swift test --filter StorageTests.
1 change: 0 additions & 1 deletion .github/workflows_disabled/supabase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ jobs:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift-version }}
- run: make dot-env
- name: Run tests
run: swift test --filter SupabaseTests.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@ iOSInjectionProject/
# Environment
.env
Secrets.swift
DotEnv.swift
lcov.info
temp_coverage
21 changes: 4 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,13 @@ endif

TEST_RUNNER_CI = $(CI)

export SECRETS
define SECRETS
enum DotEnv {
static let SUPABASE_URL = "$(SUPABASE_URL)"
static let SUPABASE_ANON_KEY = "$(SUPABASE_ANON_KEY)"
static let SUPABASE_SERVICE_ROLE_KEY = "$(SUPABASE_SERVICE_ROLE_KEY)"
}
endef

xcodebuild:
$(XCODEBUILD)

load-env:
@. ./scripts/load_env.sh

dot-env:
@echo "$$SECRETS" > Tests/IntegrationTests/DotEnv.swift

test-integration: dot-env
$(MAKE) TEST_PLAN=Integration xcodebuild
test-integration:
cd Tests/IntegrationTests && supabase start && supabase db reset
swift test --filter IntegrationTests
cd Tests/IntegrationTests && supabase stop

build-for-library-evolution:
swift build \
Expand Down
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ let package = Package(
"Supabase",
"TestHelpers",
],
resources: [.process("Fixtures")]
resources: [
.process("Fixtures"),
.process("supabase"),
]
),
.target(
name: "PostgREST",
Expand Down Expand Up @@ -149,6 +152,9 @@ let package = Package(
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
"Storage",
],
resources: [
.copy("sadcat.jpg")
]
),
.target(
Expand Down
23 changes: 14 additions & 9 deletions Sources/Realtime/WebSocket/URLSessionWebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ final class URLSessionWebSocket: WebSocket {
}

private func _scheduleReceive() {
_task.receive { [weak self] result in
Task {
let result = await Result { try await _task.receive() }
switch result {
case .success(let value): self?._handleMessage(value)
case .failure(let error): self?._closeConnectionWithError(error)
case .success(let value): _handleMessage(value)
case .failure(let error): _closeConnectionWithError(error)
}
}
}
Expand Down Expand Up @@ -168,9 +169,11 @@ final class URLSessionWebSocket: WebSocket {
return
}

_task.send(.string(text)) { [weak self] error in
if let error {
self?._closeConnectionWithError(error)
Task {
do {
try await _task.send(.string(text))
} catch {
_closeConnectionWithError(error)
}
}
}
Expand Down Expand Up @@ -198,9 +201,11 @@ final class URLSessionWebSocket: WebSocket {
return
}

_task.send(.data(binary)) { [weak self] error in
if let error {
self?._closeConnectionWithError(error)
Task {
do {
try await _task.send(.data(binary))
} catch {
_closeConnectionWithError(error)
}
}
}
Expand Down
Loading
Loading