package link.roadio.riff.storage.saf import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Assert.assertThrows import org.junit.Test import java.io.IOException class SourceRootAccessTest { @Test fun uncachedRootNeedsOnlyCurrentGrantsAndReadOnlyIdentity() { var grants = listOf("broken", "books", "music") val identities = mutableMapOf("books" to "12", "music" to "34") val access = SourceRootAccess({ grants }, { if (it == "broken") throw IOException() else identities[it] }, { String(it).toLong() }) assertEquals("music", access.resolve(34)) assertEquals("books", access.resolve(12)) grants = listOf("books") assertNull(access.resolve(34)) identities["books"] = "56" assertNull(access.resolve(12)) assertEquals("books", access.resolve(56)) grants = emptyList() assertNull(access.resolve(56)) } @Test fun grantLookupFailureIsNotAnEmptySuccessfulGrantSet() { val access = SourceRootAccess({ throw IOException("permission service failed") }, { "1" }, { 1 }) assertThrows(IOException::class.java) { access.resolve(1) } } }