go/toolchain: use ed9dc37b2b000f376a3e819cbb159e2c17a2dac6 (#514)

Updates #cleanup

Signed-off-by: kari-ts <kari@tailscale.com>
kari/androidlogs
kari-ts 1 year ago committed by kari-ts
parent 0b2a04b475
commit 3f53ed7e22

@ -0,0 +1,44 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package com.tailscale.ipn.util
import android.util.Log
import libtailscale.Libtailscale
object ExtendedLog {
var libtailscaleWrapper = LibtailscaleWrapper()
fun d(tag: String?, message: String) {
Log.d(tag, message)
libtailscaleWrapper.sendLog(tag, message)
}
fun w(tag: String, message: String) {
Log.w(tag, message)
libtailscaleWrapper.sendLog(tag, message)
}
// Overloaded function without Throwable because Java does not support default parameters
@JvmStatic
fun e(tag: String?, message: String) {
Log.e(tag, message)
libtailscaleWrapper.sendLog(tag, message)
}
fun e(tag: String?, message: String, throwable: Throwable? = null) {
if (throwable == null) {
Log.e(tag, message)
libtailscaleWrapper.sendLog(tag, message)
} else {
Log.e(tag, message, throwable)
libtailscaleWrapper.sendLog(tag, "$message ${throwable?.localizedMessage}")
}
}
class LibtailscaleWrapper {
public fun sendLog(tag: String?, message: String) {
val logTag = tag ?: ""
Libtailscale.sendLog(logTag + ": " + message)
}
}
}

@ -4,13 +4,40 @@
package com.tailcale.ipn.ui.util
import com.tailscale.ipn.ui.util.TimeUtil
import com.tailscale.ipn.util.ExtendedLog
import com.tailscale.ipn.util.ExtendedLog.LibtailscaleWrapper
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mockito.doNothing
import org.mockito.Mockito.mock
import java.time.Duration
class TimeUtilTest {
private lateinit var libtailscaleWrapperMock: LibtailscaleWrapper
private lateinit var originalWrapper: LibtailscaleWrapper
@Before
fun setUp() {
libtailscaleWrapperMock = mock(LibtailscaleWrapper::class.java)
doNothing().`when`(libtailscaleWrapperMock).sendLog(anyString(), anyString())
// Store the original wrapper so we can reset it later
originalWrapper = ExtendedLog.libtailscaleWrapper
// Inject mock into ExtendedLog
ExtendedLog.libtailscaleWrapper = libtailscaleWrapperMock
}
@After
fun tearDown() {
// Reset ExtendedLog after each test to avoid side effects
ExtendedLog.libtailscaleWrapper = originalWrapper
}
@Test
fun durationInvalidMsUnits() {
val input = "5s10ms"
@ -44,6 +71,9 @@ class TimeUtilTest {
@Test
fun testBadDInputString() {
val libtailscaleWrapperMock = mock(LibtailscaleWrapper::class.java)
doNothing().`when`(libtailscaleWrapperMock).sendLog(anyString(), anyString())
val input = "1.0yy1.0w1.0d1.0h1.0m1.0s"
val actual = TimeUtil.duration(input)
assertNull("Should return null", actual)

@ -1 +1 @@
4771bcafe5ca1554e13b2cb396336868e97781f3
ed9dc37b2b000f376a3e819cbb159e2c17a2dac6
Loading…
Cancel
Save