Skip to content

Commit f28eae6

Browse files
committed
Introduce TencentCloudCore
1 parent 91703ef commit f28eae6

File tree

6 files changed

+51
-24
lines changed

6 files changed

+51
-24
lines changed

Package.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ let package = Package(
2323
.package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.1.0")),
2424
],
2525
targets: [
26+
.target(name: "TencentCloudCore", dependencies: []),
27+
.testTarget(name: "TencentCloudCoreTests", dependencies: ["TencentCloudCore"]),
2628
.target(name: "TencentSCFRuntime", dependencies: [
2729
.byName(name: "TencentSCFRuntimeCore"),
2830
.product(name: "NIO", package: "swift-nio"),
2931
.product(name: "NIOFoundationCompat", package: "swift-nio"),
3032
]),
33+
.testTarget(name: "TencentSCFRuntimeTests", dependencies: [
34+
.byName(name: "TencentSCFRuntimeCore"),
35+
.byName(name: "TencentSCFRuntime"),
36+
]),
3137
.target(name: "TencentSCFRuntimeCore", dependencies: [
38+
.byName(name: "TencentCloudCore"),
3239
.product(name: "Logging", package: "swift-log"),
3340
.product(name: "Backtrace", package: "swift-backtrace"),
3441
.product(name: "NIOHTTP1", package: "swift-nio"),
@@ -38,11 +45,7 @@ let package = Package(
3845
.product(name: "NIOTestUtils", package: "swift-nio"),
3946
.product(name: "NIOFoundationCompat", package: "swift-nio"),
4047
]),
41-
.testTarget(name: "TencentSCFRuntimeTests", dependencies: [
42-
.byName(name: "TencentSCFRuntimeCore"),
43-
.byName(name: "TencentSCFRuntime"),
44-
]),
45-
.target(name: "TencentSCFEvents", dependencies: []),
48+
.target(name: "TencentSCFEvents", dependencies: ["TencentCloudCore"]),
4649
.testTarget(name: "TencentSCFEventsTests", dependencies: ["TencentSCFEvents"]),
4750
// testing helper
4851
.target(name: "TencentSCFTesting", dependencies: [

Sources/TencentSCFRuntimeCore/SCFContext.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import Dispatch
2929
import Logging
3030
import NIO
31+
import TencentCloudCore
3132

3233
// MARK: - InitializationContext
3334

@@ -82,7 +83,7 @@ extension SCF {
8283
public static let appid = SCF.env("TENCENTCLOUD_APPID") ?? ""
8384

8485
/// The Tencent Cloud region that the cloud function is in.
85-
public static let region = SCF.env("TENCENTCLOUD_REGION") ?? ""
86+
public static let region = TencentCloud.Region(rawValue: SCF.env("TENCENTCLOUD_REGION") ?? "")!
8687

8788
/// The name of the cloud function.
8889
public static let name = SCF.env("SCF_FUNCTIONNAME") ?? ""

Tests/TencentSCFEventsTests/TencentCloudTests.swift renamed to Tests/TencentCloudCoreTests/RegionTests.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
//
1313
//===------------------------------------------------------------------------------------===//
1414

15-
@testable import TencentSCFEvents
15+
@testable import TencentCloudCore
1616
import XCTest
1717

18-
class TencentCloudTests: XCTestCase {
18+
class TencentCloudRegionTests: XCTestCase {
1919
static let allRegions = Set(TencentCloud.Region.mainland + TencentCloud.Region.overseas)
2020
struct Wrapped<T: Codable>: Codable {
2121
let value: T
@@ -37,20 +37,4 @@ class TencentCloudTests: XCTestCase {
3737
XCTAssertEqual(region, decoded.value)
3838
}
3939
}
40-
41-
func testZoneWithRawAndCodable() throws {
42-
for region in Self.allRegions {
43-
let number = UInt8.random(in: UInt8.min ... UInt8.max)
44-
let zone = TencentCloud.Zone(rawValue: "\(region)-\(number)")
45-
XCTAssertNotNil(zone)
46-
47-
let wrapped = Wrapped(value: zone!)
48-
let json = #"{"value":"\#(zone!.rawValue)"}"#
49-
50-
let encoded = try JSONEncoder().encode(wrapped)
51-
let decoded = try JSONDecoder().decode(Wrapped<TencentCloud.Zone>.self, from: json.data(using: .utf8)!)
52-
XCTAssertEqual(String(data: encoded, encoding: .utf8), json)
53-
XCTAssertEqual(zone, decoded.value)
54-
}
55-
}
5640
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===------------------------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftTencentSCFRuntime open source project
4+
//
5+
// Copyright (c) 2020 stevapple and the SwiftTencentSCFRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftTencentSCFRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===------------------------------------------------------------------------------------===//
14+
15+
@testable import TencentCloudCore
16+
import XCTest
17+
18+
class TencentCloudZoneTests: XCTestCase {
19+
static let allRegions = Set(TencentCloud.Region.mainland + TencentCloud.Region.overseas)
20+
struct Wrapped<T: Codable>: Codable {
21+
let value: T
22+
}
23+
24+
func testZoneWithRawAndCodable() throws {
25+
for region in Self.allRegions {
26+
let number = UInt8.random(in: UInt8.min ... UInt8.max)
27+
let zone = TencentCloud.Zone(rawValue: "\(region)-\(number)")
28+
XCTAssertNotNil(zone)
29+
30+
let wrapped = Wrapped(value: zone!)
31+
let json = #"{"value":"\#(zone!.rawValue)"}"#
32+
33+
let encoded = try JSONEncoder().encode(wrapped)
34+
let decoded = try JSONDecoder().decode(Wrapped<TencentCloud.Zone>.self, from: json.data(using: .utf8)!)
35+
XCTAssertEqual(String(data: encoded, encoding: .utf8), json)
36+
XCTAssertEqual(zone, decoded.value)
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)