From 6c62ea6aa022bdb67e6a05d4206b427ceb9d8486 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Thu, 4 Apr 2024 11:06:28 -0300 Subject: [PATCH] chore: move realtime integration tests to IntegrationTests target --- .env | 3 --- .env.example | 4 ++++ .gitignore | 4 ++-- Makefile | 8 ++++---- Package.swift | 1 + Sources/TestHelpers/AsyncSequence.swift | 14 ++++++++++++++ .../AuthClientIntegrationTests.swift | 4 ++-- .../PostgrestIntegrationTests.swift | 4 ++-- .../RealtimeIntegrationTests.swift | 19 ++++++++++++++----- Tests/RealtimeTests/RealtimeTests.swift | 6 ------ scripts/{setenv.sh => dotenv.sh} | 8 ++++---- 11 files changed, 47 insertions(+), 28 deletions(-) delete mode 100644 .env create mode 100644 .env.example create mode 100644 Sources/TestHelpers/AsyncSequence.swift rename Tests/{RealtimeTests => IntegrationTests}/RealtimeIntegrationTests.swift (92%) rename scripts/{setenv.sh => dotenv.sh} (72%) mode change 100644 => 100755 diff --git a/.env b/.env deleted file mode 100644 index c8aaff0d..00000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -SUPABASE_URL= -SUPABASE_ANON_KEY= -SUPABASE_SERVICE_KEY= \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..13a1fa5e --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +# Get these from your API settings: https://supabase.com/dashboard/project/_/settings/api + +SUPABASE_URL=https://mysupabasereference.supabase.co +SUPABASE_ANON_KEY=my.supabase.anon.key diff --git a/.gitignore b/.gitignore index 41548b2b..e4db282d 100644 --- a/.gitignore +++ b/.gitignore @@ -97,6 +97,6 @@ iOSInjectionProject/ # Environment -.env.local +.env Secrets.swift -Tests/IntegrationTests/Environment.swift \ No newline at end of file +DotEnv.swift diff --git a/Makefile b/Makefile index 982af90e..a190422d 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,10 @@ PLATFORM_WATCHOS = watchOS Simulator,name=Apple Watch Series 9 (41mm) SCHEME ?= Supabase PLATFORM ?= iOS Simulator,name=iPhone 15 Pro -set-env: - @source scripts/setenv.sh > Tests/IntegrationTests/Environment.swift +dot-env: + @./scripts/dotenv.sh > Tests/IntegrationTests/DotEnv.swift -test-all: set-env +test-all: dot-env set -o pipefail && \ xcodebuild test \ -skipMacroValidation \ @@ -19,7 +19,7 @@ test-all: set-env -testPlan AllTests \ -destination platform="$(PLATFORM)" | xcpretty -test-library: set-env +test-library: dot-env set -o pipefail && \ xcodebuild test \ -skipMacroValidation \ diff --git a/Package.swift b/Package.swift index 31caf069..8c738aa6 100644 --- a/Package.swift +++ b/Package.swift @@ -79,6 +79,7 @@ let package = Package( "Auth", "TestHelpers", "PostgREST", + "Realtime", ] ), .target( diff --git a/Sources/TestHelpers/AsyncSequence.swift b/Sources/TestHelpers/AsyncSequence.swift new file mode 100644 index 00000000..0888455d --- /dev/null +++ b/Sources/TestHelpers/AsyncSequence.swift @@ -0,0 +1,14 @@ +// +// AsyncSequence.swift +// +// +// Created by Guilherme Souza on 04/04/24. +// + +import Foundation + +extension AsyncSequence { + package func collect() async rethrows -> [Element] { + try await reduce(into: [Element]()) { $0.append($1) } + } +} diff --git a/Tests/IntegrationTests/AuthClientIntegrationTests.swift b/Tests/IntegrationTests/AuthClientIntegrationTests.swift index 5be01ce8..b9382f2f 100644 --- a/Tests/IntegrationTests/AuthClientIntegrationTests.swift +++ b/Tests/IntegrationTests/AuthClientIntegrationTests.swift @@ -14,9 +14,9 @@ import XCTest final class AuthClientIntegrationTests: XCTestCase { let authClient = AuthClient( configuration: AuthClient.Configuration( - url: URL(string: "\(Environment.SUPABASE_URL)/auth/v1")!, + url: URL(string: "\(DotEnv.SUPABASE_URL)/auth/v1")!, headers: [ - "apikey": Environment.SUPABASE_ANON_KEY, + "apikey": DotEnv.SUPABASE_ANON_KEY, ], localStorage: InMemoryLocalStorage(), logger: nil diff --git a/Tests/IntegrationTests/PostgrestIntegrationTests.swift b/Tests/IntegrationTests/PostgrestIntegrationTests.swift index 11ff1b48..6336fcfc 100644 --- a/Tests/IntegrationTests/PostgrestIntegrationTests.swift +++ b/Tests/IntegrationTests/PostgrestIntegrationTests.swift @@ -36,9 +36,9 @@ struct User: Codable, Hashable { @available(iOS 15.0.0, macOS 12.0.0, tvOS 13.0, *) final class IntegrationTests: XCTestCase { let client = PostgrestClient( - url: URL(string: "\(Environment.SUPABASE_URL)/rest/v1")!, + url: URL(string: "\(DotEnv.SUPABASE_URL)/rest/v1")!, headers: [ - "Apikey": Environment.SUPABASE_ANON_KEY, + "Apikey": DotEnv.SUPABASE_ANON_KEY, ], logger: nil ) diff --git a/Tests/RealtimeTests/RealtimeIntegrationTests.swift b/Tests/IntegrationTests/RealtimeIntegrationTests.swift similarity index 92% rename from Tests/RealtimeTests/RealtimeIntegrationTests.swift rename to Tests/IntegrationTests/RealtimeIntegrationTests.swift index f7a81a8c..80e3c789 100644 --- a/Tests/RealtimeTests/RealtimeIntegrationTests.swift +++ b/Tests/IntegrationTests/RealtimeIntegrationTests.swift @@ -9,22 +9,31 @@ import ConcurrencyExtras import CustomDump import PostgREST @testable import Realtime +import Supabase +import TestHelpers import XCTest +struct Logger: SupabaseLogger { + func log(message: SupabaseLogMessage) { + print(message.description) + } +} + final class RealtimeIntegrationTests: XCTestCase { let realtime = RealtimeClientV2( config: RealtimeClientV2.Configuration( - url: URL(string: "http://localhost:54321/realtime/v1")!, - apiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" + url: URL(string: "\(DotEnv.SUPABASE_URL)/realtime/v1")!, + apiKey: DotEnv.SUPABASE_ANON_KEY, + logger: Logger() ) ) let db = PostgrestClient( - url: URL(string: "http://localhost:54321/rest/v1")!, + url: URL(string: "\(DotEnv.SUPABASE_URL)/rest/v1")!, headers: [ - "apikey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU", + "apikey": DotEnv.SUPABASE_ANON_KEY, ], - logger: nil + logger: Logger() ) func testBroadcast() async throws { diff --git a/Tests/RealtimeTests/RealtimeTests.swift b/Tests/RealtimeTests/RealtimeTests.swift index 5737e873..414deb9d 100644 --- a/Tests/RealtimeTests/RealtimeTests.swift +++ b/Tests/RealtimeTests/RealtimeTests.swift @@ -148,12 +148,6 @@ final class RealtimeTests: XCTestCase { } } -extension AsyncSequence { - func collect() async rethrows -> [Element] { - try await reduce(into: [Element]()) { $0.append($1) } - } -} - extension RealtimeMessageV2 { static let subscribeToMessages = Self( joinRef: "1", diff --git a/scripts/setenv.sh b/scripts/dotenv.sh old mode 100644 new mode 100755 similarity index 72% rename from scripts/setenv.sh rename to scripts/dotenv.sh index c04b6a45..88cef004 --- a/scripts/setenv.sh +++ b/scripts/dotenv.sh @@ -3,14 +3,14 @@ env_file="${1:-.env}" if [[ -f "$env_file" ]]; then - echo "enum Environment {" + echo "enum DotEnv {" while IFS='=' read -r key value || [[ -n "$key" ]]; do - if [[ -n "$key" ]]; then + if [[ -n "$key" && ! "$key" =~ ^# ]]; then if [[ -z "$value" ]]; then value=$(eval "echo \$$key") fi echo " static let $key = \"$value\"" fi - done < "$env_file" + done < <(grep -v '^#' "$env_file") echo "}" -fi \ No newline at end of file +fi