-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests for custom badge generation - connects to #24
- Loading branch information
1 parent
e6ad368
commit 7fc5a62
Showing
7 changed files
with
139 additions
and
27 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
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
50 changes: 50 additions & 0 deletions
50
src/test/groovy/io/github/devatherock/artifactory/service/DockerBadgeServiceSpec.groovy
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,50 @@ | ||
package io.github.devatherock.artifactory.service | ||
|
||
import io.github.devatherock.artifactory.config.ArtifactoryProperties | ||
import io.github.devatherock.artifactory.entities.ArtifactoryFolderInfo | ||
import io.github.devatherock.artifactory.util.BadgeGenerator | ||
import io.micronaut.http.client.BlockingHttpClient | ||
import io.micronaut.http.client.HttpClient | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
/** | ||
* Test class for {@link DockerBadgeService} | ||
*/ | ||
class DockerBadgeServiceSpec extends Specification { | ||
@Subject | ||
DockerBadgeService dockerBadgeService | ||
|
||
BlockingHttpClient httpClient = HttpClient.create(new URL('http://localhost:8081')).toBlocking() | ||
BadgeGenerator badgeGenerator = Mock() | ||
ArtifactoryProperties config = new ArtifactoryProperties(url: 'http://localhost:8081') | ||
|
||
void setup() { | ||
config.init() | ||
dockerBadgeService = new DockerBadgeService(httpClient, badgeGenerator, config) | ||
} | ||
|
||
void 'test get version badge value'() { | ||
expect: | ||
dockerBadgeService.getVersionBadgeValue(new ArtifactoryFolderInfo(path: path)) == outputVersion | ||
|
||
where: | ||
path | outputVersion | ||
'docker/devatherock/simple-slack/1.1.0' | 'v1.1.0' | ||
'docker/devatherock/simple-slack/latest' | 'latest' | ||
} | ||
|
||
void 'test format download count'() { | ||
expect: | ||
dockerBadgeService.formatDownloadCount(downloadCount) == formattedCount | ||
|
||
where: | ||
downloadCount | formattedCount | ||
450 | '450' | ||
1249 | '1.2k' | ||
1251 | '1.3k' | ||
1_100_000 | '1.1M' | ||
1_100_000_000 | '1.1G' | ||
1_100_000_000_000 | '1100G' | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/groovy/io/github/devatherock/artifactory/util/BadgeGeneratorSpec.groovy
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,52 @@ | ||
package io.github.devatherock.artifactory.util | ||
|
||
import io.github.devatherock.artifactory.config.ShieldsIOProperties | ||
import io.github.devatherock.artifactory.service.ShieldsIOClient | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
/** | ||
* Test class for {@link BadgeGenerator} | ||
*/ | ||
class BadgeGeneratorSpec extends Specification { | ||
@Subject | ||
BadgeGenerator badgeGenerator | ||
|
||
ShieldsIOClient shieldsIOClient = Mock() | ||
ShieldsIOProperties config = new ShieldsIOProperties(enabled: false) | ||
|
||
void setup() { | ||
badgeGenerator = new BadgeGenerator(shieldsIOClient, config) | ||
} | ||
|
||
void 'test generate badge - custom generator'() { | ||
given: | ||
String expectedResponse = [ | ||
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="144" height="20" role="img" aria-label="docker pulls: 47">', | ||
'<title>docker pulls: 47</title>', | ||
'<linearGradient id="s" x2="0" y2="100%">', | ||
'<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>', | ||
'<stop offset="1" stop-opacity=".1"/>', | ||
'</linearGradient>', | ||
'<clipPath id="r">', | ||
'<rect width="144" height="20" rx="3" fill="#fff"/>', | ||
'</clipPath>', | ||
'<g clip-path="url(#r)">', | ||
'<rect width="112" height="20" fill="#555"/>', | ||
'<rect x="112" width="32" height="20" fill="#007ec6"/>', | ||
'<rect width="144" height="20" fill="url(#s)"/>', | ||
'</g>', | ||
'<g font-family="monospace">', | ||
'<text aria-hidden="true" x="0" y="15" fill="#fff" xml:space="preserve"> docker pulls </text>', | ||
'<text aria-hidden="true" x="112" y="15" fill="#fff" xml:space="preserve"> 47 </text>', | ||
'</g>', | ||
'</svg>' | ||
].join('') | ||
|
||
when: | ||
String badge = badgeGenerator.generateBadge('docker pulls', '47') | ||
|
||
then: | ||
badge == expectedResponse | ||
} | ||
} |