Skip to content

Commit

Permalink
ci: run integrations tests on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Jan 17, 2025
1 parent dc5a9f7 commit d800a95
Show file tree
Hide file tree
Showing 16 changed files with 889 additions and 228 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: lcov.info


xcodebuild:
name: xcodebuild (15)
runs-on: macos-14
Expand Down Expand Up @@ -112,6 +111,25 @@ jobs:
if: matrix.skip_release != '1'
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Release PLATFORM="${{ matrix.platform }}" xcodebuild

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

# linux:
# name: linux
# strategy:
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/integration-tests.yml

This file was deleted.

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
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ load-env:
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
57 changes: 17 additions & 40 deletions Tests/IntegrationTests/AuthClientIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
// Created by Guilherme Souza on 27/03/24.
//

@testable import Auth
import ConcurrencyExtras
import CustomDump
import TestHelpers
import XCTest

@testable import Auth

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Expand Down Expand Up @@ -55,7 +56,7 @@ final class AuthClientIntegrationTests: XCTestCase {
let password = mockPassword()

let metadata: [String: AnyJSON] = [
"test": .integer(42),
"test": .integer(42)
]

let response = try await authClient.signUp(
Expand All @@ -74,24 +75,6 @@ final class AuthClientIntegrationTests: XCTestCase {
}
}

// func testSignUpAndSignInWithPhone() async throws {
// try await XCTAssertAuthChangeEvents([.initialSession, .signedIn, .signedOut, .signedIn]) {
// let phone = mockPhoneNumber()
// let password = mockPassword()
// let metadata: [String: AnyJSON] = [
// "test": .integer(42),
// ]
// let response = try await authClient.signUp(phone: phone, password: password, data: metadata)
// XCTAssertNotNil(response.session)
// XCTAssertEqual(response.user.phone, phone)
// XCTAssertEqual(response.user.userMetadata["test"], 42)
//
// try await authClient.signOut()
//
// try await authClient.signIn(phone: phone, password: password)
// }
// }

func testSignInWithEmail_invalidEmail() async throws {
let email = mockEmail()
let password = mockPassword()
Expand All @@ -108,13 +91,6 @@ final class AuthClientIntegrationTests: XCTestCase {
}
}

// func testSignInWithOTP_usingEmail() async throws {
// let email = mockEmail()
//
// try await authClient.signInWithOTP(email: email)
// try await authClient.verifyOTP(email: email, token: "123456", type: .magiclink)
// }

func testSignOut_otherScope_shouldSignOutLocally() async throws {
try await XCTAssertAuthChangeEvents([.initialSession, .signedIn]) {
let email = mockEmail()
Expand Down Expand Up @@ -170,7 +146,7 @@ final class AuthClientIntegrationTests: XCTestCase {
func testUserIdentities() async throws {
let session = try await signUpIfNeededOrSignIn(email: mockEmail(), password: mockPassword())
let identities = try await authClient.userIdentities()
expectNoDifference(session.user.identities, identities)
expectNoDifference(session.user.identities?.map(\.id), identities.map(\.id))
}

func testUnlinkIdentity_withOnlyOneIdentity() async throws {
Expand Down Expand Up @@ -291,10 +267,10 @@ final class AuthClientIntegrationTests: XCTestCase {
}
}

private func mockEmail(length: Int = Int.random(in: 5 ... 10)) -> String {
private func mockEmail(length: Int = Int.random(in: 5...10)) -> String {
var username = ""
for _ in 0 ..< length {
let randomAscii = Int.random(in: 97 ... 122) // ASCII values for lowercase letters
for _ in 0..<length {
let randomAscii = Int.random(in: 97...122) // ASCII values for lowercase letters
let randomCharacter = Character(UnicodeScalar(randomAscii)!)
username.append(randomCharacter)
}
Expand All @@ -303,13 +279,13 @@ final class AuthClientIntegrationTests: XCTestCase {

private func mockPhoneNumber() -> String {
// Generate random country code (1 to 3 digits)
let countryCode = String(format: "%d", Int.random(in: 1 ... 999))
let countryCode = String(format: "%d", Int.random(in: 1...999))

// Generate random area code (3 digits)
let areaCode = String(format: "%03d", Int.random(in: 100 ... 999))
let areaCode = String(format: "%03d", Int.random(in: 100...999))

// Generate random subscriber number (7 digits)
let subscriberNumber = String(format: "%07d", Int.random(in: 1000000 ... 9999999))
let subscriberNumber = String(format: "%07d", Int.random(in: 1_000_000...9_999_999))

// Format the phone number in E.164 format
let phoneNumber = "\(countryCode)\(areaCode)\(subscriberNumber)"
Expand All @@ -322,12 +298,13 @@ final class AuthClientIntegrationTests: XCTestCase {
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+"
var password = ""

for _ in 0 ..< length {
let randomIndex = Int.random(in: 0 ..< allowedCharacters.count)
let character = allowedCharacters[allowedCharacters.index(
allowedCharacters.startIndex,
offsetBy: randomIndex
)]
for _ in 0..<length {
let randomIndex = Int.random(in: 0..<allowedCharacters.count)
let character = allowedCharacters[
allowedCharacters.index(
allowedCharacters.startIndex,
offsetBy: randomIndex
)]
password.append(character)
}

Expand Down
23 changes: 22 additions & 1 deletion Tests/IntegrationTests/Postgrest/PostgresTransformsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ final class PostgrestTransformsTests: XCTestCase {
"status" : "OFFLINE",
"username" : "kiwicopple"
},
{
"age_range" : "[20,30)",
"catchphrase" : "'json' 'test'",
"data" : {
"foo" : {
"bar" : {
"nested" : "value"
},
"baz" : "string value"
}
},
"status" : "ONLINE",
"username" : "jsonuser"
},
{
"age_range" : "[20,30)",
"catchphrase" : "'fat' 'rat'",
Expand Down Expand Up @@ -74,6 +88,13 @@ final class PostgrestTransformsTests: XCTestCase {
assertInlineSnapshot(of: res, as: .json) {
"""
[
{
"channel_id" : 3,
"data" : null,
"id" : 4,
"message" : "Some message on channel wihtout details",
"username" : "supabot"
},
{
"channel_id" : 2,
"data" : null,
Expand Down Expand Up @@ -265,7 +286,7 @@ final class PostgrestTransformsTests: XCTestCase {
let res = try await client.from("users").select().csv().execute().string()
assertInlineSnapshot(of: res, as: .json) {
#"""
"username,data,age_range,status,catchphrase\nsupabot,,\"[1,2)\",ONLINE,\"'cat' 'fat'\"\nkiwicopple,,\"[25,35)\",OFFLINE,\"'bat' 'cat'\"\nawailas,,\"[25,35)\",ONLINE,\"'bat' 'rat'\"\ndragarcia,,\"[20,30)\",ONLINE,\"'fat' 'rat'\""
"username,data,age_range,status,catchphrase\nsupabot,,\"[1,2)\",ONLINE,\"'cat' 'fat'\"\nkiwicopple,,\"[25,35)\",OFFLINE,\"'bat' 'cat'\"\nawailas,,\"[25,35)\",ONLINE,\"'bat' 'rat'\"\ndragarcia,,\"[20,30)\",ONLINE,\"'fat' 'rat'\"\njsonuser,\"{\"\"foo\"\": {\"\"bar\"\": {\"\"nested\"\": \"\"value\"\"}, \"\"baz\"\": \"\"string value\"\"}}\",\"[20,30)\",ONLINE,\"'json' 'test'\""
"""#
}
}
Expand Down
Loading

0 comments on commit d800a95

Please sign in to comment.