-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Ability to publish attachments from Gradle plugin
- Loading branch information
Showing
7 changed files
with
197 additions
and
2 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
3 changes: 3 additions & 0 deletions
3
...ers/gradle-plugin/src/main/groovy/projektor/plugin/ProjektorPublishPluginExtension.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package projektor.plugin | ||
|
||
import org.gradle.api.file.FileTree | ||
|
||
class ProjektorPublishPluginExtension { | ||
boolean autoPublish = true | ||
boolean autoPublishOnFailureOnly = false | ||
String serverUrl | ||
boolean manualPublishEnabled = true | ||
String publishToken | ||
List<String> additionalResultsDirs = [] | ||
List<FileTree> attachments = [] | ||
} |
21 changes: 21 additions & 0 deletions
21
...rs/gradle-plugin/src/main/groovy/projektor/plugin/attachments/AttachmentsPublisher.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,21 @@ | ||
package projektor.plugin.attachments | ||
|
||
import org.gradle.api.file.FileTree | ||
import org.gradle.api.logging.Logger | ||
|
||
class AttachmentsPublisher { | ||
private final AttachmentsClient attachmentsClient | ||
private final Logger logger | ||
|
||
AttachmentsPublisher(AttachmentsClient attachmentsClient, Logger logger) { | ||
this.attachmentsClient = attachmentsClient | ||
this.logger = logger | ||
} | ||
|
||
void publishAttachments(String publicId, List<FileTree> attachmentFileTrees) { | ||
List<File> attachments = attachmentFileTrees.collect { it.files }.flatten() | ||
logger.info("Sending ${attachments.size()} attachments to Projektor report ${publicId}") | ||
|
||
attachments.each { attachmentsClient.sendAttachmentToServer(publicId, it) } | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
.../src/test/groovy/projektor/plugin/testkit/attachments/AttachmentsSingleProjectSpec.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,119 @@ | ||
package projektor.plugin.testkit.attachments | ||
|
||
import com.github.tomakehurst.wiremock.verification.LoggedRequest | ||
import org.gradle.testkit.runner.GradleRunner | ||
import projektor.plugin.AttachmentsWireMockStubber | ||
import projektor.plugin.testkit.SingleProjectSpec | ||
import projektor.plugin.testkit.util.AttachmentsWriter | ||
|
||
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||
|
||
class AttachmentsSingleProjectSpec extends SingleProjectSpec { | ||
AttachmentsWireMockStubber attachmentsStubber = new AttachmentsWireMockStubber(wireMockRule) | ||
|
||
def "should publish results and attachments to server"() { | ||
given: | ||
File attachmentsDir1 = AttachmentsWriter.createAttachmentsDir(projectRootDir, 'attachments1') | ||
AttachmentsWriter.writeAttachmentFile(attachmentsDir1, "attachment1.txt", "Here is attachment 1") | ||
AttachmentsWriter.writeAttachmentFile(attachmentsDir1, "attachment2.txt", "Here is attachment 2") | ||
File attachmentsDir2 = AttachmentsWriter.createAttachmentsDir(projectRootDir, 'attachments2') | ||
AttachmentsWriter.writeAttachmentFile(attachmentsDir2, "attachment3.txt", "Here is attachment 3") | ||
|
||
buildFile << """ | ||
projektor { | ||
serverUrl = '${serverUrl}' | ||
attachments = [fileTree(dir: 'attachments1', include: '**/*.txt'), fileTree(dir: 'attachments2', include: '**/*.txt')] | ||
} | ||
""".stripIndent() | ||
|
||
File testDirectory = specWriter.createTestDirectory(projectRootDir) | ||
specWriter.writeSpecFile(testDirectory, "SampleSpec") | ||
|
||
String resultsId = "ABC123" | ||
resultsStubber.stubResultsPostSuccess(resultsId) | ||
attachmentsStubber.stubAttachmentPostSuccess(resultsId, "attachment1.txt") | ||
attachmentsStubber.stubAttachmentPostSuccess(resultsId, "attachment2.txt") | ||
attachmentsStubber.stubAttachmentPostSuccess(resultsId, "attachment3.txt") | ||
|
||
when: | ||
def result = GradleRunner.create() | ||
.withProjectDir(projectRootDir.root) | ||
.withArguments('test') | ||
.withPluginClasspath() | ||
.build() | ||
|
||
then: | ||
result.task(":test").outcome == SUCCESS | ||
|
||
and: | ||
!result.output.contains("Projektor plugin enabled but no server specified") | ||
result.output.contains("View Projektor report at: ${serverUrl}/tests/${resultsId}") | ||
|
||
and: | ||
List<LoggedRequest> resultsRequests = resultsStubber.findResultsRequests() | ||
resultsRequests.size() == 1 | ||
|
||
and: | ||
List<LoggedRequest> attachmentRequests = attachmentsStubber.findAttachmentsRequests(resultsId) | ||
attachmentRequests.size() == 3 | ||
} | ||
|
||
def "should publish results and attachments with publish task"() { | ||
given: | ||
File attachmentsDir = AttachmentsWriter.createAttachmentsDir(projectRootDir, 'attachments') | ||
AttachmentsWriter.writeAttachmentFile(attachmentsDir, "attachment1.txt", "Here is attachment 1") | ||
AttachmentsWriter.writeAttachmentFile(attachmentsDir, "attachment2.txt", "Here is attachment 2") | ||
|
||
buildFile << """ | ||
projektor { | ||
serverUrl = '${serverUrl}' | ||
autoPublish = false | ||
attachments = [fileTree(dir: 'attachments', include: '**/*.txt')] | ||
} | ||
""".stripIndent() | ||
|
||
File testDirectory = specWriter.createTestDirectory(projectRootDir) | ||
specWriter.writeSpecFile(testDirectory, "SampleSpec") | ||
|
||
String resultsId = "ABC123" | ||
resultsStubber.stubResultsPostSuccess(resultsId) | ||
attachmentsStubber.stubAttachmentPostSuccess(resultsId, "attachment1.txt") | ||
attachmentsStubber.stubAttachmentPostSuccess(resultsId, "attachment2.txt") | ||
|
||
when: | ||
def testResult = GradleRunner.create() | ||
.withProjectDir(projectRootDir.root) | ||
.withArguments('test') | ||
.withPluginClasspath() | ||
.build() | ||
|
||
then: | ||
testResult.task(":test").outcome == SUCCESS | ||
|
||
and: | ||
resultsStubber.findResultsRequests().size() == 0 | ||
|
||
when: | ||
def publishResults = GradleRunner.create() | ||
.withProjectDir(projectRootDir.root) | ||
.withArguments('publishResults', '--info') | ||
.withPluginClasspath() | ||
.build() | ||
|
||
println publishResults.output | ||
|
||
then: | ||
publishResults.task(":publishResults").outcome == SUCCESS | ||
|
||
and: | ||
publishResults.output.contains("View Projektor report at: ${serverUrl}/tests/${resultsId}") | ||
|
||
and: | ||
List<LoggedRequest> resultsRequests = resultsStubber.findResultsRequests() | ||
resultsRequests.size() == 1 | ||
|
||
and: | ||
List<LoggedRequest> attachmentRequests = attachmentsStubber.findAttachmentsRequests(resultsId) | ||
attachmentRequests.size() == 2 | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...hers/gradle-plugin/src/test/groovy/projektor/plugin/testkit/util/AttachmentsWriter.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,24 @@ | ||
package projektor.plugin.testkit.util | ||
|
||
import org.junit.rules.TemporaryFolder | ||
|
||
class AttachmentsWriter { | ||
static File createAttachmentsDir(TemporaryFolder projectDir, String dirName) { | ||
projectDir.newFolder(dirName) | ||
} | ||
|
||
static File createAttachmentsDir(File projectDir, String dirName) { | ||
File dir = new File(projectDir, dirName) | ||
dir.mkdirs() | ||
return dir | ||
} | ||
|
||
static File writeAttachmentFile(File attachmentsDir, String fileName, String contents) { | ||
File attachmentFile = new File(attachmentsDir, fileName) | ||
attachmentFile.createNewFile() | ||
|
||
attachmentFile.text = contents | ||
|
||
return attachmentFile | ||
} | ||
} |