-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip Bugsnag initialization if user disabled gcloud analytics (#678)
- Loading branch information
1 parent
19f6108
commit 3a27b3b
Showing
6 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
test_runner/src/main/kotlin/ftl/config/BugsnagInitHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ftl.config | ||
|
||
import com.bugsnag.Bugsnag | ||
import java.nio.file.Paths | ||
|
||
internal object BugsnagInitHelper { | ||
|
||
private const val GSUTIL_FOLDER = ".gsutil" | ||
private const val ANALYTICS_FILE = "analytics-uuid" | ||
private const val DISABLED = "DISABLED" | ||
private const val FLANK_API_KEY = "3d5f8ba4ee847d6bb51cb9c347eda74f" | ||
|
||
internal fun initBugsnag(useMock: Boolean) = | ||
Paths.get(System.getProperty("user.home"), "$GSUTIL_FOLDER/$ANALYTICS_FILE").toFile().run { | ||
if (useMock) null | ||
else if (exists() && readText().trim() == DISABLED) null | ||
else Bugsnag(FLANK_API_KEY) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
test_runner/src/test/kotlin/ftl/config/BugsnagInitHelperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ftl.config | ||
|
||
import ftl.log.LogbackLogger | ||
import io.mockk.every | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkAll | ||
import org.junit.After | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertNull | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import java.io.File | ||
import java.util.UUID | ||
|
||
private const val GSUTIL_FOLDER = ".gsutil" | ||
private const val ANALYTICS_FILE = "analytics-uuid" | ||
private const val DISABLED = "DISABLED\n" | ||
|
||
class BugsnagInitHelperTest { | ||
|
||
private val helper = BugsnagInitHelper | ||
|
||
@get:Rule | ||
val folder = TemporaryFolder() | ||
|
||
@Before | ||
fun setUp() { | ||
LogbackLogger.Bugsnag.isEnabled = false | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
unmockkAll() | ||
} | ||
|
||
@Test | ||
fun `should not create Bugsnag object if user has analytics disabled`() { | ||
mockkStatic(System::class) | ||
every { System.getProperty("user.home") } returns folder.root.absolutePath | ||
|
||
val subfolder = folder.newFolder(GSUTIL_FOLDER) | ||
File(subfolder, ANALYTICS_FILE).also { it.writeText(DISABLED) } | ||
|
||
assertNull(helper.initBugsnag(useMock = false)) | ||
} | ||
|
||
@Test | ||
fun `should not create Bugsnag object if user provided analytics-uuid`() { | ||
mockkStatic(System::class) | ||
every { System.getProperty("user.home") } returns folder.root.absolutePath | ||
|
||
val subfolder = folder.newFolder(GSUTIL_FOLDER) | ||
File(subfolder, ANALYTICS_FILE).also { it.writeText(UUID.randomUUID().toString()) } | ||
|
||
assertNotNull(helper.initBugsnag(useMock = false)) | ||
} | ||
|
||
@Test | ||
fun `should create Bugsnag object if mock server used`() { | ||
mockkStatic(System::class) | ||
every { System.getProperty("user.home") } returns folder.root.absolutePath | ||
|
||
val subfolder = folder.newFolder(GSUTIL_FOLDER) | ||
File(subfolder, ANALYTICS_FILE).also { it.writeText(UUID.randomUUID().toString()) } | ||
|
||
assertNull(helper.initBugsnag(useMock = true)) | ||
} | ||
} |