Skip to content

Commit

Permalink
More integration tests - connects to #24
Browse files Browse the repository at this point in the history
  • Loading branch information
devatherock committed Feb 6, 2021
1 parent 0836506 commit d4cc498
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 98 deletions.
39 changes: 38 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ executors:

version: 2.1
jobs:
publish_release:
executor: jdk-executor
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: ~/artifactory-badge
- run: |
TAG=${CIRCLE_TAG#v}
DEV_TAG=${CIRCLE_SHA1:0:8}
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker pull devatherock/artifactory-badge:$DEV_TAG
docker tag devatherock/artifactory-badge:$DEV_TAG devatherock/artifactory-badge:$TAG
docker push devatherock/artifactory-badge:$TAG
notify_success:
<<: *slack_image
<<: *resource_class
Expand Down Expand Up @@ -92,7 +107,7 @@ workflows:
- build
image: devatherock/artifactory-badge
attach-at: ~/artifactory-badge
tag: "0.1.14,latest"
tag: "${CIRCLE_SHA1:0:8},latest"
use-remote-docker: true
docker-username: DOCKER_USERNAME
- notify_success:
Expand All @@ -107,6 +122,28 @@ workflows:
- slack-webhook
requires:
- publish
release:
jobs:
- publish_release:
context:
- docker-credentials
filters:
branches:
only: non-existent-branch
tags:
only: /^v[0-9\.]+$/
- notify_success:
context:
- docker-credentials
- slack-webhook
requires:
- publish_release
- notify_failure:
context:
- docker-credentials
- slack-webhook
requires:
- publish_release
pr_check:
jobs:
- gradle/run:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![CircleCI](https://circleci.com/gh/devatherock/artifactory-badge.svg?style=svg)](https://circleci.com/gh/devatherock/artifactory-badge)
[![Version](https://img.shields.io/docker/v/devatherock/artifactory-badge?sort=date)](https://hub.docker.com/r/devatherock/artifactory-badge/)
[![Version](https://img.shields.io/docker/v/devatherock/artifactory-badge?sort=semver)](https://hub.docker.com/r/devatherock/artifactory-badge/)
[![Coverage Status](https://coveralls.io/repos/github/devatherock/artifactory-badge/badge.svg?branch=master)](https://coveralls.io/github/devatherock/artifactory-badge?branch=master)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=artifactory-badge&metric=alert_status)](https://sonarcloud.io/component_measures?id=artifactory-badge&metric=alert_status&view=list)
[![Docker Pulls](https://img.shields.io/docker/pulls/devatherock/artifactory-badge.svg)](https://hub.docker.com/r/devatherock/artifactory-badge/)
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ ext.jacoco = [
// Should be removed when all tests have been written
coverageThresholds: [
'io.github.devatherock.artifactory.service.DockerBadgeService': [
'BRANCH': 0.28,
'COMPLEXITY': 0.32,
'INSTRUCTION': 0.70,
'LINE': 0.70
'BRANCH': 0.57,
'COMPLEXITY': 0.48,
'INSTRUCTION': 0.91,
'LINE': 0.90
],
'io.github.devatherock.artifactory.util.BadgeGenerator': [
'BRANCH': 0.50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.devatherock.artifactory.controllers

import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import io.github.devatherock.test.TestUtil
import io.micronaut.http.HttpRequest
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
Expand All @@ -12,7 +13,8 @@ import spock.lang.Specification

import javax.inject.Inject

import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;

/**
* Test class for {@link DockerController}
Expand Down Expand Up @@ -46,15 +48,16 @@ class DockerControllerSpec extends Specification {

and:
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}")
.willReturn(WireMock.okJson(getFoldersResponse())))
.willReturn(WireMock.okJson(
TestUtil.getFoldersResponse('/devatherock/simple-slack','2020-10-01T00:00:00.000Z'))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/1.1.0/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('1.1.0', 10))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('1.1.0', 10))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/1.1.2/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('1.1.2', 20))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('1.1.2', 20))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/latest/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('latest', 30))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('latest', 30))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/abcdefgh/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('abcdefgh', 40))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('abcdefgh', 40))))
WireMock.givenThat(WireMock.get(WireMock.urlPathEqualTo('/static/v1'))
.withQueryParam('label', equalTo('docker pulls'))
.withQueryParam('message', equalTo('100'))
Expand All @@ -67,6 +70,16 @@ class DockerControllerSpec extends Specification {
.queryParam('package', packageName).build()))

then:
WireMock.verify(1, WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/1.1.0/manifest.json?stats")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/1.1.2/manifest.json?stats")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/latest/manifest.json?stats")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/abcdefgh/manifest.json?stats")))
WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlPathEqualTo("/static/v1")))
badge == 'dummyBadge'
}

Expand All @@ -76,15 +89,16 @@ class DockerControllerSpec extends Specification {

and:
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}")
.willReturn(WireMock.okJson(getFoldersResponse())))
.willReturn(WireMock.okJson(
TestUtil.getFoldersResponse('/devatherock/simple-slack', '2020-10-01T00:00:00.000Z'))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/1.1.0/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('1.1.0', 10))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('1.1.0', 10))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/1.1.2/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('1.1.2', 20))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('1.1.2', 20))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/latest/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('latest', 30))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('latest', 30))))
WireMock.givenThat(WireMock.get("/artifactory/api/storage/${packageName}/abcdefgh/manifest.json?stats")
.willReturn(WireMock.okJson(getManifestStats('abcdefgh', 40))))
.willReturn(WireMock.okJson(TestUtil.getManifestStats('abcdefgh', 40))))
WireMock.givenThat(WireMock.get(WireMock.urlPathEqualTo('/static/v1'))
.withQueryParam('label', equalTo('downloads'))
.withQueryParam('message', equalTo('100'))
Expand All @@ -98,6 +112,16 @@ class DockerControllerSpec extends Specification {
.queryParam('label', 'downloads').build()))

then:
WireMock.verify(1, WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/1.1.0/manifest.json?stats")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/1.1.2/manifest.json?stats")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/latest/manifest.json?stats")))
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/api/storage/${packageName}/abcdefgh/manifest.json?stats")))
WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlPathEqualTo("/static/v1")))
badge == 'dummyBadge'
}

Expand All @@ -107,7 +131,7 @@ class DockerControllerSpec extends Specification {

and:
WireMock.givenThat(WireMock.get("/artifactory/${packageName}/latest/manifest.json")
.willReturn(WireMock.okJson(getManifest())))
.willReturn(WireMock.okJson(TestUtil.getManifest())))
WireMock.givenThat(WireMock.get(WireMock.urlPathEqualTo('/static/v1'))
.withQueryParam('label', equalTo('image size'))
.withQueryParam('message', equalTo('11 MB'))
Expand All @@ -120,6 +144,9 @@ class DockerControllerSpec extends Specification {
.queryParam('package', packageName).build()))

then:
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/${packageName}/latest/manifest.json")))
WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlPathEqualTo("/static/v1")))
badge == 'dummyBadge'
}

Expand All @@ -129,7 +156,7 @@ class DockerControllerSpec extends Specification {

and:
WireMock.givenThat(WireMock.get("/artifactory/${packageName}/1.2.0/manifest.json")
.willReturn(WireMock.okJson(getManifest())))
.willReturn(WireMock.okJson(TestUtil.getManifest())))
WireMock.givenThat(WireMock.get(WireMock.urlPathEqualTo('/static/v1'))
.withQueryParam('label', equalTo('size'))
.withQueryParam('message', equalTo('11 MB'))
Expand All @@ -144,6 +171,9 @@ class DockerControllerSpec extends Specification {
.queryParam('label', 'size').build()))

then:
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/${packageName}/1.2.0/manifest.json")))
WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlPathEqualTo("/static/v1")))
badge == 'dummyBadge'
}

Expand All @@ -153,7 +183,7 @@ class DockerControllerSpec extends Specification {

and:
WireMock.givenThat(WireMock.get("/artifactory/${packageName}/latest/manifest.json")
.willReturn(WireMock.okJson(getManifest())))
.willReturn(WireMock.okJson(TestUtil.getManifest())))
WireMock.givenThat(WireMock.get(WireMock.urlPathEqualTo('/static/v1'))
.withQueryParam('label', equalTo('layers'))
.withQueryParam('message', equalTo('2'))
Expand All @@ -166,6 +196,9 @@ class DockerControllerSpec extends Specification {
.queryParam('package', packageName).build()))

then:
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/${packageName}/latest/manifest.json")))
WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlPathEqualTo("/static/v1")))
badge == 'dummyBadge'
}

Expand All @@ -175,7 +208,7 @@ class DockerControllerSpec extends Specification {

and:
WireMock.givenThat(WireMock.get("/artifactory/${packageName}/1.2.0/manifest.json")
.willReturn(WireMock.okJson(getManifest())))
.willReturn(WireMock.okJson(TestUtil.getManifest())))
WireMock.givenThat(WireMock.get(WireMock.urlPathEqualTo('/static/v1'))
.withQueryParam('label', equalTo('number of layers'))
.withQueryParam('message', equalTo('2'))
Expand All @@ -190,72 +223,9 @@ class DockerControllerSpec extends Specification {
.queryParam('label', 'number of layers').build()))

then:
WireMock.verify(1,
WireMock.getRequestedFor(urlEqualTo("/artifactory/${packageName}/1.2.0/manifest.json")))
WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlPathEqualTo("/static/v1")))
badge == 'dummyBadge'
}

String getFoldersResponse() {
"""{
"repo": "docker",
"path": "/devatherock/simple-slack",
"created": "2018-09-23T18:02:56.147Z",
"createdBy": "devatherock",
"lastModified": "2018-09-23T18:02:56.147Z",
"modifiedBy": "devatherock",
"lastUpdated": "2018-09-23T18:02:56.147Z",
"children": [
{
"uri": "/1.1.0",
"folder": true
},
{
"uri": "/1.1.2",
"folder": true
},
{
"uri": "/latest",
"folder": true
},
{
"uri": "/abcdefgh",
"folder": true
}
],
"uri": "http://localhost:8081/artifactory/api/storage/docker/devatherock/simple-slack"
}"""
}

String getManifestStats(String tag, int downloadCount) {
"""{
"uri": "http://localhost:8081/artifactory/docker/devatherock/simple-slack/${tag}/manifest.json",
"downloadCount": ${downloadCount},
"lastDownloaded": 1602863958001,
"lastDownloadedBy": "devatherock",
"remoteDownloadCount": 0,
"remoteLastDownloaded": 0
}"""
}

String getManifest() {
"""{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 3027,
"digest": "sha256:9fe1c24da9391a4d7346200a997c06c7c900466181081af7953a2a15c9fffd7c"
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 10485760,
"digest": "sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10"
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 1048576,
"digest": "sha256:f910a506b6cb1dbec766725d70356f695ae2bf2bea6224dbe8c7c6ad4f3664a2"
}
]
}"""
}
}
Loading

0 comments on commit d4cc498

Please sign in to comment.