30
30
import java .nio .file .SimpleFileVisitor ;
31
31
import java .nio .file .attribute .BasicFileAttributes ;
32
32
import org .apache .beam .sdk .options .PipelineOptionsFactory ;
33
+ import org .apache .beam .sdk .util .ReleaseInfo ;
33
34
import org .junit .Before ;
34
35
import org .junit .Ignore ;
35
36
import org .junit .Test ;
40
41
@ RunWith (JUnit4 .class )
41
42
public class PrismLocatorTest {
42
43
44
+ private static final ReleaseInfo RELEASE_INFO = ReleaseInfo .getReleaseInfo ();
43
45
private static final Path DESTINATION_DIRECTORY = prismBinDirectory ();
44
46
45
47
@ Before
@@ -61,61 +63,102 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
61
63
}
62
64
63
65
@ Test
64
- public void givenVersionOverride_thenResolves () throws IOException {
65
- assertThat (Files .exists (DESTINATION_DIRECTORY )).isFalse ();
66
+ public void givenVersionOverride_thenResolvesLocation () throws IOException {
67
+ PrismPipelineOptions options = options ();
68
+ options .setPrismVersionOverride ("2.57.0-RC1" );
69
+
70
+ PrismLocator underTest = new PrismLocator (options );
71
+ String got = underTest .resolveSource ();
72
+
73
+ assertThat (got )
74
+ .contains (
75
+ "https://github.com/apache/beam/releases/download/v" + RELEASE_INFO .getSdkVersion ());
76
+ assertThat (got ).contains ("apache_beam-v2.57.0-RC1-prism" );
77
+ assertThat (got ).contains (".zip" );
78
+ }
79
+
80
+ // This testcase validates a user override to download a different release version specifically.
81
+ @ Test
82
+ public void givenHttpPrismLocationOption_thenResolvesLocation () throws IOException {
83
+ PrismPipelineOptions options = options ();
84
+ String want =
85
+ "https://github.com/apache/beam/releases/download/v2.57.0/apache_beam-v2.57.0-prism-darwin-arm64.zip" ;
86
+ options .setPrismLocation (want );
87
+
88
+ PrismLocator underTest = new PrismLocator (options );
89
+ String got = underTest .resolveSource ();
90
+
91
+ assertThat (got ).isEqualTo (want );
92
+ }
93
+
94
+ // This testcase is the Release Validation behavior, where we provide an RC option, but
95
+ // need to resolve the download for the non-RC version.
96
+ // Copy the URL directly, and set the location, override the file's RC version with the final
97
+ // version.
98
+ @ Test
99
+ public void givenRCGithubTagPrismLocationOption_thenResolvesLocation () {
66
100
PrismPipelineOptions options = options ();
101
+ options .setPrismLocation ("https://github.com/apache/beam/releases/tag/v2.57.0-RC1/" );
67
102
options .setPrismVersionOverride ("2.57.0" );
103
+
68
104
PrismLocator underTest = new PrismLocator (options );
69
- String got = underTest .resolve ();
70
- assertThat (got ).contains (DESTINATION_DIRECTORY .toString ());
71
- assertThat (got ).contains ("2.57.0" );
72
- Path gotPath = Paths .get (got );
73
- assertThat (Files .exists (gotPath )).isTrue ();
105
+ String got = underTest .resolveSource ();
106
+
107
+ assertThat (got )
108
+ .contains (
109
+ "https://github.com/apache/beam/releases/download/v2.57.0-RC1/apache_beam-v2.57.0-prism" );
110
+ assertThat (got ).contains (".zip" );
74
111
}
75
112
76
113
@ Test
77
- public void givenHttpPrismLocationOption_thenResolves () throws IOException {
78
- assertThat (Files .exists (DESTINATION_DIRECTORY )).isFalse ();
114
+ public void givenRCGithubTagPrismLocationOptionNoTrailingSlash_thenResolvesLocation () {
79
115
PrismPipelineOptions options = options ();
80
- options .setPrismLocation (
81
- "https://github.com/apache/beam/releases/download/v2.57.0/apache_beam-v2.57.0-prism-darwin-arm64.zip" );
116
+ options .setPrismLocation ("https://github.com/apache/beam/releases/tag/v2.57.0-RC2" );
117
+ options .setPrismVersionOverride ("2.57.0" );
118
+
82
119
PrismLocator underTest = new PrismLocator (options );
83
- String got = underTest .resolve ();
84
- assertThat (got ).contains (DESTINATION_DIRECTORY .toString ());
85
- Path gotPath = Paths .get (got );
86
- assertThat (Files .exists (gotPath )).isTrue ();
120
+ String got = underTest .resolveSource ();
121
+
122
+ assertThat (got )
123
+ .contains (
124
+ "https://github.com/apache/beam/releases/download/v2.57.0-RC2/apache_beam-v2.57.0-prism" );
125
+ assertThat (got ).contains (".zip" );
87
126
}
88
127
89
128
@ Test
90
129
public void givenFilePrismLocationOption_thenResolves () throws IOException {
91
130
assertThat (Files .exists (DESTINATION_DIRECTORY )).isFalse ();
92
131
PrismPipelineOptions options = options ();
93
132
options .setPrismLocation (getLocalPrismBuildOrIgnoreTest ());
133
+
94
134
PrismLocator underTest = new PrismLocator (options );
95
135
String got = underTest .resolve ();
136
+
96
137
assertThat (got ).contains (DESTINATION_DIRECTORY .toString ());
97
138
Path gotPath = Paths .get (got );
98
139
assertThat (Files .exists (gotPath )).isTrue ();
99
140
}
100
141
101
142
@ Test
102
- public void givenGithubTagPrismLocationOption_thenThrows () {
143
+ public void givenIncorrectGithubPrismLocationOption_thenThrows () {
103
144
PrismPipelineOptions options = options ();
145
+ // This is an incorrect github download path. Downloads are under /download/ not tag.
104
146
options .setPrismLocation (
105
147
"https://github.com/apache/beam/releases/tag/v2.57.0/apache_beam-v2.57.0-prism-darwin-amd64.zip" );
148
+
106
149
PrismLocator underTest = new PrismLocator (options );
107
- IllegalArgumentException error =
108
- assertThrows (IllegalArgumentException .class , underTest ::resolve );
109
- assertThat (error .getMessage ())
110
- .contains (
111
- "Provided --prismLocation URL is not an Apache Beam Github Release page URL or download URL" );
150
+
151
+ RuntimeException error = assertThrows (RuntimeException .class , underTest ::resolve );
152
+ // Message should contain the incorrectly constructed download link.
153
+ assertThat (error .getMessage ()).contains (".zip/apache_beam" );
112
154
}
113
155
114
156
@ Test
115
157
@ Ignore // TODO: use mock site. Currently failing with response code 500 instead of 404
116
158
public void givenPrismLocation404_thenThrows () {
117
159
PrismPipelineOptions options = options ();
118
160
options .setPrismLocation ("https://example.com/i/dont/exist.zip" );
161
+
119
162
PrismLocator underTest = new PrismLocator (options );
120
163
RuntimeException error = assertThrows (RuntimeException .class , underTest ::resolve );
121
164
assertThat (error .getMessage ()).contains ("NotFoundException" );
0 commit comments