Skip to content

Commit

Permalink
Ci tests improvement (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
HopeBaron authored Apr 20, 2021
1 parent af746c3 commit 274e454
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/deployment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: Kotlin CI

on:
push:
tags-ignore:
- '**' # We don't want this to run on tags pushes
pull_request:
release:
types: [published]
Expand Down Expand Up @@ -39,11 +41,10 @@ jobs:
if: |
!contains(github.event.head_commit.message, '[publish skip]') && !contains(github.event.pull_request.title, '[publish skip]')
&& github.event_name != 'pull_request' && github.ref != 'refs/heads/master'
needs: build
env:
KORD_TEST_TOKEN: ${{ secrets.KORD_TEST_TOKEN }}
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
NEXUS_USER: ${{ secrets.NEXUS_USER }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.signingKey }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.7.0-RC3

## Fixes

* Unhandled missing access when trying to get vanity url with the feature disabled. #264

# 0.7.0-RC2

## Additions
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/kotlin/behavior/GuildBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ interface GuildBehavior : KordEntity, Strategizable {
* @throws [RestRequestException] if something went wrong during the request.
*/
suspend fun getVanityUrl(): String? {
val identifier = catchDiscordError(JsonErrorCode.InviteCodeInvalidOrTaken) {
val identifier = catchDiscordError(JsonErrorCode.InviteCodeInvalidOrTaken, JsonErrorCode.MissingAccess) {
kord.rest.guild.getVanityInvite(id).code
} ?: return null
return "https://discord.gg/$identifier"
Expand Down Expand Up @@ -935,8 +935,8 @@ suspend inline fun GuildBehavior.bulkEditSlashCommandPermissions(noinline builde
}

kord.slashCommands.bulkEditApplicationCommandPermissions(
kord.selfId,
id,
builder
kord.selfId,
id,
builder
)
}
2 changes: 2 additions & 0 deletions core/src/test/kotlin/KordTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onCompletion
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import java.util.concurrent.CountDownLatch

@EnabledIfEnvironmentVariable(named = "KORD_TEST_TOKEN", matches = ".+")
internal class KordTest {

@Test
Expand Down
24 changes: 10 additions & 14 deletions core/src/test/kotlin/StrategyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import dev.kord.cache.api.put
import dev.kord.core.Kord
import dev.kord.core.supplier.EntitySupplyStrategy
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.*
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Disabled
@EnabledIfEnvironmentVariable(named = "KORD_TEST_TOKEN", matches = ".+")
class StrategyTest {

lateinit var kord: Kord
Expand All @@ -23,28 +20,27 @@ class StrategyTest {
}

@Test
@EnabledIfEnvironmentVariable(named = "TARGET_BRANCH", matches = "master")
@Order(1)
fun `rest only`() = runBlocking {
kord.with(EntitySupplyStrategy.rest).getSelf()
val fromRest = kord.with(EntitySupplyStrategy.rest).getSelfOrNull()
val inCache = kord.with(EntitySupplyStrategy.cache).getSelfOrNull()
assertNull(inCache)
assertNotNull(fromRest)
}

@Test
@Disabled
@Order(3)
fun `cache only`() = runBlocking {
val self = kord.with(EntitySupplyStrategy.rest).getSelf()
kord.cache.put(self.data)

val inCache = kord.with(EntitySupplyStrategy.cache).getSelf()
assertEquals(self, inCache)
val inCache = kord.with(EntitySupplyStrategy.cache).getSelfOrNull()
assertNotNull(inCache)
}

@Test
@EnabledIfEnvironmentVariable(named = "TARGET_BRANCH", matches = "master")
@Order(2)
fun `cache falls back to rest`() = runBlocking {
val cache = kord.with(EntitySupplyStrategy.cache)
val inCache = cache.getSelf()
val inCache = cache.getSelfOrNull()

assertNull(inCache)

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/regression/CacheMissRegression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CrashingHandler(val client: HttpClient) : RequestHandler {
}
}

@EnabledIfEnvironmentVariable(named = "TARGET_BRANCH", matches = "master")
@EnabledIfEnvironmentVariable(named = "KORD_TEST_TOKEN", matches = ".+")
class CacheMissingRegressions {
lateinit var kord: Kord

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/rest/RestTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun imageBinary(path: String): Image {

@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@EnabledIfEnvironmentVariable(named = "TARGET_BRANCH", matches = "master")
@EnabledIfEnvironmentVariable(named = "KORD_TEST_TOKEN", matches = ".+")
class RestServiceTest {

private val publicGuildId = Snowflake(322850917248663552)
Expand Down

0 comments on commit 274e454

Please sign in to comment.