forked from elastic/elasticsearch
/
DistributionDownloadPluginFuncTest.groovy
148 lines (121 loc) · 5.04 KB
/
DistributionDownloadPluginFuncTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.gradle
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Unroll
import static org.elasticsearch.gradle.fixtures.DistributionDownloadFixture.withMockedDistributionDownload
class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
@Unroll
def "extracted #distType version can be resolved"() {
given:
buildFile << applyPluginAndSetupDistro(version, platform)
when:
def result = withMockedDistributionDownload(version, platform, gradleRunner('setupDistro', '-i')) {
build()
}
then:
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
assertExtractedDistroCreated("build/distro")
where:
version | platform | distType
VersionProperties.getElasticsearch() | ElasticsearchDistribution.Platform.LINUX | "current"
"8.1.0-SNAPSHOT" | ElasticsearchDistribution.Platform.LINUX | "bwc"
"7.0.0" | ElasticsearchDistribution.Platform.WINDOWS | "released"
}
def "transformed versions are kept across builds"() {
given:
def version = VersionProperties.getElasticsearch()
def platform = ElasticsearchDistribution.Platform.LINUX
buildFile << applyPluginAndSetupDistro(version, platform)
buildFile << """
apply plugin:'base'
"""
when:
def runner = gradleRunner('clean', 'setupDistro', '-i', '-g', gradleUserHome)
def unpackingMessage = "Unpacking elasticsearch-${version}-linux-${Architecture.current().classifier}.tar.gz " +
"using SymbolicLinkPreservingUntarTransform"
def result = withMockedDistributionDownload(version, platform, runner) {
// initial run
def firstRun = build()
assertOutputContains(firstRun.output, unpackingMessage)
// 2nd invocation
build()
}
then:
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
assertOutputMissing(result.output, unpackingMessage)
}
def "transforms are reused across projects"() {
given:
def version = VersionProperties.getElasticsearch()
def platform = ElasticsearchDistribution.Platform.LINUX
3.times {
settingsFile << """
include ':sub-$it'
"""
}
buildFile.text = """
import org.elasticsearch.gradle.Architecture
plugins {
id 'elasticsearch.distribution-download'
}
subprojects {
apply plugin: 'elasticsearch.distribution-download'
${setupTestDistro(version, platform)}
${setupDistroTask()}
}
"""
when:
def runner = gradleRunner('setupDistro', '-i', '-g', gradleUserHome)
def result = withMockedDistributionDownload(version, platform, runner) {
build()
}
then:
result.tasks.size() == 3
result.output.count("Unpacking elasticsearch-${version}-linux-${Architecture.current().classifier}.tar.gz " +
"using SymbolicLinkPreservingUntarTransform") == 1
}
private boolean assertExtractedDistroCreated(String relativePath) {
File distroExtracted = new File(testProjectDir.root, relativePath)
assert distroExtracted.exists()
assert distroExtracted.isDirectory()
assert new File(distroExtracted, "elasticsearch-1.2.3/bin/elasticsearch").exists()
true
}
private static String applyPluginAndSetupDistro(String version, ElasticsearchDistribution.Platform platform) {
"""
import org.elasticsearch.gradle.Architecture
plugins {
id 'elasticsearch.distribution-download'
}
${setupTestDistro(version, platform)}
${setupDistroTask()}
"""
}
private static String setupTestDistro(String version, ElasticsearchDistribution.Platform platform) {
return """
elasticsearch_distributions {
test_distro {
version = "$version"
type = "archive"
platform = "$platform"
architecture = Architecture.current();
}
}
"""
}
private static String setupDistroTask() {
return """
tasks.register("setupDistro", Sync) {
from(elasticsearch_distributions.test_distro)
into("build/distro")
}
"""
}
}