Skip to content

Commit

Permalink
chore: clean up some deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Nov 23, 2023
1 parent 3bb216f commit 5256ed3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
13 changes: 6 additions & 7 deletions src/test/kotlin/io/snyk/plugin/analytics/ItlyHelperTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.snyk.plugin.analytics

import io.snyk.plugin.services.SnykApplicationSettingsStateService
import org.hamcrest.core.IsEqual.equalTo
import org.junit.Assert.assertThat
import org.junit.Assert.assertEquals
import org.junit.Test
import snyk.advisor.AdvisorPackageManager
import snyk.analytics.AnalysisIsReady.AnalysisType
Expand All @@ -21,7 +20,7 @@ class ItlyHelperTest {

val actualProducts = getSelectedProducts(settings)

assertThat(actualProducts.size, equalTo(0))
assertEquals(0, actualProducts.size)
}

@Test
Expand All @@ -35,8 +34,8 @@ class ItlyHelperTest {

val actualProducts = getSelectedProducts(settings)

assertThat(actualProducts.size, equalTo(1))
assertThat(actualProducts[0], equalTo(AnalysisType.SNYK_OPEN_SOURCE.analysisType))
assertEquals(1, actualProducts.size)
assertEquals(AnalysisType.SNYK_OPEN_SOURCE.analysisType, actualProducts[0])
}

@Test
Expand All @@ -45,7 +44,7 @@ class ItlyHelperTest {

val actualEcosystem = npmPackageManager.getEcosystem()

assertThat(actualEcosystem, equalTo(HealthScoreIsClicked.Ecosystem.NPM))
assertEquals(HealthScoreIsClicked.Ecosystem.NPM, actualEcosystem)
}

@Test
Expand All @@ -54,6 +53,6 @@ class ItlyHelperTest {

val actualEcosystem = pythonPackageManager.getEcosystem()

assertThat(actualEcosystem, equalTo(HealthScoreIsClicked.Ecosystem.PYTHON))
assertEquals(HealthScoreIsClicked.Ecosystem.PYTHON, actualEcosystem)
}
}
11 changes: 5 additions & 6 deletions src/test/kotlin/snyk/amplitude/api/VariantTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package snyk.amplitude.api

import com.google.gson.Gson
import org.hamcrest.core.IsEqual.equalTo
import org.hamcrest.core.IsNull.notNullValue
import org.junit.Assert.assertThat
import org.junit.Assert.assertEquals
import org.junit.Test

class VariantTest {
Expand All @@ -15,8 +14,8 @@ class VariantTest {

val variant = gson.fromJson(json, Variant::class.java)

assertThat(variant, notNullValue())
assertThat(variant.value, equalTo("on"))
assertEquals(notNullValue(), variant)
assertEquals("on", variant.value)
}

@Test
Expand All @@ -25,7 +24,7 @@ class VariantTest {

val variant = gson.fromJson(json, Variant::class.java)

assertThat(variant, notNullValue())
assertThat(variant.value, equalTo("on"))
assertEquals(notNullValue(), variant)
assertEquals("on", variant.value)
}
}
76 changes: 34 additions & 42 deletions src/test/kotlin/snyk/common/CustomEndpointsTest.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package snyk.common

import io.mockk.mockk
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.services.SnykApplicationSettingsStateService
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertTrue
import junit.framework.TestCase.assertEquals
import org.hamcrest.core.IsEqual.equalTo
import org.junit.Assert.assertThat
import org.junit.Test
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.net.URI
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.services.SnykApplicationSettingsStateService
import org.junit.After

class CustomEndpointsTest {
@Before
Expand All @@ -35,38 +33,38 @@ class CustomEndpointsTest {
val endpointForNull = resolveCustomEndpoint(null)
val endpointForEmpty = resolveCustomEndpoint("")

assertThat(endpointForNull, equalTo("https://app.snyk.io/api"))
assertThat(endpointForEmpty, equalTo("https://app.snyk.io/api"))
assertEquals("https://app.snyk.io/api", endpointForNull)
assertEquals("https://app.snyk.io/api", endpointForEmpty)
}

@Test
fun `resolveCustomEndpoint removes all trailing slashes if present`() {
val endpointWithSingleTrailingSlash = resolveCustomEndpoint("https://on-prem.internal/api")
val endpointWithMultipleTrailingSlashes = resolveCustomEndpoint("https://on-prem.internal/api///")

assertThat(endpointWithSingleTrailingSlash, equalTo("https://on-prem.internal/api"))
assertThat(endpointWithMultipleTrailingSlashes, equalTo("https://on-prem.internal/api"))
assertEquals("https://on-prem.internal/api", endpointWithSingleTrailingSlash)
assertEquals("https://on-prem.internal/api", endpointWithMultipleTrailingSlashes)
}

@Test
fun `removeTrailingSlashesIfPresent do not return malformed(syntactically incorrect) url`() {
val endpointWithNoHost = "http:/".removeTrailingSlashesIfPresent()

assertThat(endpointWithNoHost, equalTo("http:/"))
assertEquals("http:/", endpointWithNoHost)
}

@Test
fun `isSnykCodeAvailable returns true for SaaS deployments`() {
val snykCodeAvailableForProduction = isSnykCodeAvailable("https://snyk.io/api")
val snykCodeAvailableForDevelopment = isSnykCodeAvailable("https://dev.snyk.io/api")

assertThat(snykCodeAvailableForProduction, equalTo(true))
assertThat(snykCodeAvailableForDevelopment, equalTo(true))
assertEquals(true, snykCodeAvailableForProduction)
assertEquals(true, snykCodeAvailableForDevelopment)
}

@Test
fun `isSnykCodeAvailable returns true if local engine is enabled`() {
every { pluginSettings().localCodeEngineUrl } returns "http://foo.bar/api"
every { pluginSettings().localCodeEngineUrl } returns "https://foo.bar/api"
every { pluginSettings().localCodeEngineEnabled } returns true

assertEquals(isSnykCodeAvailable("https://foo.bar/api"), true)
Expand All @@ -76,78 +74,72 @@ class CustomEndpointsTest {
fun `isSnykCodeAvailable returns true for Single Tenant deployments`() {
val snykCodeAvailable = isSnykCodeAvailable("https://app.random-uuid.snyk.io/api")

assertThat(snykCodeAvailable, equalTo(true))
assertEquals(true, snykCodeAvailable)
}

@Test
fun `toSnykApiUrlV1 returns correct API URL`() {
assertThat(URI("https://snyk.io/api").toSnykAPIv1().toString(), equalTo("https://api.snyk.io/v1/"))
assertThat(URI("https://app.snyk.io/api").toSnykAPIv1().toString(), equalTo("https://api.snyk.io/v1/"))
assertThat(URI("https://app.eu.snyk.io/api").toSnykAPIv1().toString(), equalTo("https://api.eu.snyk.io/v1/"))
assertThat(URI("https://dev.snyk.io/api").toSnykAPIv1().toString(), equalTo("https://api.dev.snyk.io/v1/"))
assertEquals("https://api.snyk.io/v1/", URI("https://snyk.io/api").toSnykAPIv1().toString())
assertEquals("https://api.snyk.io/v1/", URI("https://app.snyk.io/api").toSnykAPIv1().toString())
assertEquals("https://api.eu.snyk.io/v1/", URI("https://app.eu.snyk.io/api").toSnykAPIv1().toString())
assertEquals("https://api.dev.snyk.io/v1/", URI("https://dev.snyk.io/api").toSnykAPIv1().toString())
}

@Test
fun `toSnykCodeApiUrl returns correct deeproxy url for SaaS deployments`() {
val apiUrlForProduction = toSnykCodeApiUrl("https://snyk.io/api")
val apiUrlForDevelopment = toSnykCodeApiUrl("https://dev.snyk.io/api")

assertThat(apiUrlForProduction, equalTo("https://deeproxy.snyk.io/"))
assertThat(apiUrlForDevelopment, equalTo("https://deeproxy.dev.snyk.io/"))
assertEquals("https://deeproxy.snyk.io/", apiUrlForProduction)
assertEquals("https://deeproxy.dev.snyk.io/", apiUrlForDevelopment)
}

@Test
fun `toSnykCodeApiUrl returns local engine URL if local engine is enabled`() {
every { pluginSettings().localCodeEngineUrl } returns "http://foo.bar/api"
every { pluginSettings().localCodeEngineUrl } returns "https://foo.bar/api"
every { pluginSettings().localCodeEngineEnabled } returns true
val apiUrlForProduction = toSnykCodeApiUrl("https://snyk.io/api")

assertEquals(apiUrlForProduction, "http://foo.bar/api")
assertEquals("https://foo.bar/api", apiUrlForProduction)
}

@Test
fun `toSnykCodeApiUrl returns correct deeproxy url for SaaS deployments using api url`() {
val apiUrlForProduction = toSnykCodeApiUrl("https://app.eu.snyk.io/api")
val apiUrlForDevelopment = toSnykCodeApiUrl("https://dev.app.eu.snyk.io/api")

assertThat(apiUrlForProduction, equalTo("https://deeproxy.eu.snyk.io/"))
assertThat(apiUrlForDevelopment, equalTo("https://deeproxy.dev.eu.snyk.io/"))
assertEquals("https://deeproxy.eu.snyk.io/", apiUrlForProduction)
assertEquals("https://deeproxy.dev.eu.snyk.io/", apiUrlForDevelopment)
}

@Test
fun `toSnykCodeApiUrl returns correct deeproxy url for Single Tenant deployments`() {
val apiUrl = toSnykCodeApiUrl("https://app.random-uuid.snyk.io/api")

assertThat(apiUrl, equalTo("https://deeproxy.random-uuid.snyk.io/"))
assertEquals("https://deeproxy.random-uuid.snyk.io/", apiUrl)
}

@Test
fun `toSnykCodeSettingsUrl returns correct settings url for SaaS deployments`() {
assertThat(toSnykCodeSettingsUrl("https://snyk.io/api"), equalTo("https://app.snyk.io/manage/snyk-code"))
assertThat(
toSnykCodeSettingsUrl("https://dev.snyk.io/api"), equalTo("https://app.dev.snyk.io/manage/snyk-code")
)
assertThat(
toSnykCodeSettingsUrl("https://dev.app.eu.snyk.io"), equalTo("https://app.dev.eu.snyk.io/manage/snyk-code")
)
assertThat(
toSnykCodeSettingsUrl("https://something.eu.snyk.io"), equalTo("https://app.snyk.io/manage/snyk-code")
)
assertEquals("https://app.snyk.io/manage/snyk-code", toSnykCodeSettingsUrl("https://snyk.io/api"))
assertEquals("https://app.dev.snyk.io/manage/snyk-code", toSnykCodeSettingsUrl("https://dev.snyk.io/api"))
assertEquals("https://app.dev.eu.snyk.io/manage/snyk-code", toSnykCodeSettingsUrl("https://dev.app.eu.snyk.io"))
assertEquals("https://app.snyk.io/manage/snyk-code", toSnykCodeSettingsUrl("https://something.eu.snyk.io"))
}

@Test
fun `toSnykCodeSettingsUrl returns URL unedited for local engine`() {
every { pluginSettings().localCodeEngineUrl } returns "http://foo.bar/api"
every { pluginSettings().localCodeEngineUrl } returns "https://foo.bar/api"
every { pluginSettings().localCodeEngineEnabled } returns true

assertEquals(toSnykCodeSettingsUrl("http://foo.bar/api"), "http://foo.bar/api")
assertEquals(toSnykCodeSettingsUrl("https://foo.bar/api"), "https://foo.bar/api")
}

@Test
fun `toSnykCodeSettingsUrl returns correct settings url for Single Tenant deployments`() {
val settingsUrl = toSnykCodeSettingsUrl("https://app.random-uuid.snyk.io/api")

assertThat(settingsUrl, equalTo("https://app.random-uuid.snyk.io/manage/snyk-code"))
assertEquals("https://app.random-uuid.snyk.io/manage/snyk-code", settingsUrl)
}

@Test
Expand Down Expand Up @@ -198,7 +190,7 @@ class CustomEndpointsTest {

@Test
fun `needsSnykToken return true if local-engine is enabled`() {
every { pluginSettings().localCodeEngineUrl } returns "http://foo.bar"
every { pluginSettings().localCodeEngineUrl } returns "https://foo.bar"
every { pluginSettings().localCodeEngineEnabled } returns true
val uri = "https://foo.bar/api"

Expand Down

0 comments on commit 5256ed3

Please sign in to comment.