Skip to content

Commit

Permalink
Update default value for enabling cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hwidiapradja committed Jun 7, 2024
1 parent 592bd0f commit d98af98
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Sources/Core/Models/Environment/EnvironmentValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension EnvironmentValues {
var analyticsBaseURL: URL? { self.url(for: "BUILDKITE_ANALYTICS_BASE_URL") }

var isAnalyticsDebugEnabled: Bool { self.bool(for: "BUILDKITE_ANALYTICS_DEBUG_ENABLED") ?? false }
var isAnalyticsCachingEnabled: Bool { self.bool(for: "BUILDKITE_ANALYTICS_CACHING_ENABLED") ?? false }
var isAnalyticsCachingEnabled: Bool { self.bool(for: "BUILDKITE_ANALYTICS_CACHING_ENABLED") ?? true }

var analyticsKey: String? { self.string(for: "BUILDKITE_ANALYTICS_KEY") }
var analyticsUrl: String? { self.string(for: "BUILDKITE_ANALYTICS_URL") }
Expand Down
4 changes: 2 additions & 2 deletions Tests/CoreTests/ApiClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ApiClientTests: XCTestCase {
baseURL: URL(string: "http://api.test.com/")!,
session: session
)
let results = TestResults.json(runEnv: .init(key: "key", isCacheEnabled: false), data: [])
let results = TestResults.json(runEnv: .init(key: "key", isCacheEnabled: true), data: [])

let (value, _) = try await api.data(for: .upload(results), as: Response.self)

Expand All @@ -30,7 +30,7 @@ final class ApiClientTests: XCTestCase {
XCTAssertEqual(request.httpMethod, "POST")
XCTAssertEqual(
request.httpBodyDictionary,
["format": "json", "run_env": ["key": "key", "isCacheEnabled": "false"], "data": NSArray()]
["format": "json", "run_env": ["key": "key", "isCacheEnabled": "true"], "data": NSArray()]
)
}
}
8 changes: 4 additions & 4 deletions Tests/CoreTests/CollectorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class CollectorTests: XCTestCase {
let environment = EnvironmentValues(values: [:])
let collector = TestCollector(environment: environment)
let observer = try XCTUnwrap(collector.observer, "Observer should be initialised")
XCTAssertNil(observer.uploader, "Uploader should not be initialised without an api key")
XCTAssertNotNil(observer.uploader, "Uploader should be initialised without an api key")
}

func testDefaultCollectorWithUploader() throws {
Expand All @@ -16,11 +16,11 @@ final class CollectorTests: XCTestCase {
XCTAssertNotNil(observer.uploader, "Uploader should be initialised when provided an api key")
}

func testCollectorWithCachingEnabledAndWithoutAPIKey() throws {
let environment = EnvironmentValues(values: ["BUILDKITE_ANALYTICS_CACHING_ENABLED": "true"])
func testCollectorWithoutCachingEnabledAndWithoutAPIKey() throws {
let environment = EnvironmentValues(values: ["BUILDKITE_ANALYTICS_CACHING_ENABLED": "false"])
let collector = TestCollector(environment: environment)
let observer = try XCTUnwrap(collector.observer, "Observer should be created by default")
XCTAssertNotNil(observer.uploader, "Uploader should be initialised when cache is enabled and api key is not provided")
XCTAssertNil(observer.uploader, "Uploader should not be initialised when cache is disabled and api key is not provided")
}

func testCollectorIsDisabled() {
Expand Down
16 changes: 8 additions & 8 deletions Tests/CoreTests/RunEnvironmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class RunEnvironmentTests: XCTestCase {
message: "message",
version: TestCollector.version,
collector: TestCollector.name,
isCacheEnabled: false
isCacheEnabled: true
)
)
}
Expand Down Expand Up @@ -57,7 +57,7 @@ final class RunEnvironmentTests: XCTestCase {
message: "Build #buildNumber on branch main",
version: TestCollector.version,
collector: TestCollector.name,
isCacheEnabled: false
isCacheEnabled: true
)
)
}
Expand Down Expand Up @@ -90,7 +90,7 @@ final class RunEnvironmentTests: XCTestCase {
message: "Run #runNumber attempt #runAttempt of workflowName, started by username",
version: TestCollector.version,
collector: TestCollector.name,
isCacheEnabled: false
isCacheEnabled: true
)
)
}
Expand Down Expand Up @@ -120,7 +120,7 @@ final class RunEnvironmentTests: XCTestCase {
message: "Build #buildNumber of workflow: workflowName",
version: TestCollector.version,
collector: TestCollector.name,
isCacheEnabled: false
isCacheEnabled: true
)
)
}
Expand All @@ -140,7 +140,7 @@ final class RunEnvironmentTests: XCTestCase {
executionNameSuffix: "executionNameSuffix",
version: "version",
collector: "collector",
isCacheEnabled: false,
isCacheEnabled: true,
customEnvironment: [
"custom_key": "customKey",
"tags": ["A", "B", "C"],
Expand All @@ -167,7 +167,7 @@ final class RunEnvironmentTests: XCTestCase {
"execution_name_suffix": "executionNameSuffix",
"version": "version",
"collector": "collector",
"isCacheEnabled": "false",
"isCacheEnabled": "true",
"custom_key": "customKey",
"tags": ["A", "B", "C"],
]
Expand All @@ -177,7 +177,7 @@ final class RunEnvironmentTests: XCTestCase {
func testCustomEnvironmentTakesPrecedence() throws {
let runEnvironment = RunEnvironment(
key: "key",
isCacheEnabled: false,
isCacheEnabled: true,
customEnvironment: [
"key": "customKey",
]
Expand All @@ -191,7 +191,7 @@ final class RunEnvironmentTests: XCTestCase {
json as? NSDictionary,
[
"key": "customKey",
"isCacheEnabled": "false"
"isCacheEnabled": "true"
]
)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/CoreTests/TestResultsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class TestResultsTests: XCTestCase {
)

let testResults = TestResults.json(
runEnv: RunEnvironment(key: "test", isCacheEnabled: false),
runEnv: RunEnvironment(key: "test", isCacheEnabled: true),
data: [
.init(test: testSuccess, span: .init(section: "span0")),
.init(test: testFailure, span: .init(section: "span1")),
Expand All @@ -103,7 +103,7 @@ final class TestResultsTests: XCTestCase {
"run_env": NSDictionary(
dictionary: [
"key": "test",
"isCacheEnabled": "false",
"isCacheEnabled": "true",
]
),
"data": [
Expand Down
5 changes: 4 additions & 1 deletion Tests/CoreTests/UploadClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ final class UploadClientTests: XCTestCase {

func testSaveDataShouldNotSaveWhenCachingIsDisabled() {
let fileController = FileControllerSpy()
var environment = EnvironmentValues().runEnvironment()
environment.isCacheEnabled = false

let uploadClient = UploadClient.local(
runEnvironment: EnvironmentValues().runEnvironment(),
runEnvironment: environment,
fileController: fileController
)

Expand Down

0 comments on commit d98af98

Please sign in to comment.