Skip to content

Commit e55e935

Browse files
authored
Merge pull request #590 from segmentio/schema-e2e
Migrate tests to webhook-e2e
2 parents d949848 + 66a5044 commit e55e935

File tree

7 files changed

+39
-67
lines changed

7 files changed

+39
-67
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: Copy E2E Test Credentials
1919
command: |
2020
if [ "${RUN_E2E_TESTS}" == "true" ]; then
21-
echo "RUNSCOPE_TOKEN=${RUNSCOPE_TOKEN}" >> "analytics-samples/analytics-sample/e2e_test.properties"
21+
echo "WEBHOOK_AUTH_USERNAME=${WEBHOOK_AUTH_USERNAME}" >> "analytics-samples/analytics-sample/e2e_test.properties"
2222
fi
2323
- run:
2424
name: Build
@@ -32,7 +32,7 @@ jobs:
3232
unzip -qq google-cloud-sdk.zip
3333
./google-cloud-sdk/bin/gcloud config set project analytics-android-e2e-test
3434
./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file secret.json
35-
./google-cloud-sdk/bin/gcloud firebase test android run --app analytics-samples/analytics-sample/build/outputs/apk/debug/analytics-sample-debug.apk --test analytics-samples/analytics-sample/build/outputs/apk/androidTest/debug/analytics-sample-debug-androidTest.apk --device-ids sailfish,hammerhead --os-version-ids 19,21,22,23,24,25,26,27 --locales en,fr --orientations portrait
35+
./google-cloud-sdk/bin/gcloud firebase test android run --app analytics-samples/analytics-sample/build/outputs/apk/debug/analytics-sample-debug.apk --test analytics-samples/analytics-sample/build/outputs/apk/androidTest/debug/analytics-sample-debug-androidTest.apk --device-ids Nexus6,hammerhead,sailfish --os-version-ids 19,21,22,23,24,25,26,27
3636
fi
3737
- save_cache:
3838
paths:

analytics-samples/analytics-sample/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ apply plugin: 'com.f2prateek.javafmt'
33

44
apply from: rootProject.file('gradle/android.gradle')
55

6-
def RUNSCOPE_TOKEN = ""
6+
def WEBHOOK_AUTH_USERNAME = ""
77
def RUN_E2E_TESTS = false
88

9-
// e2e_test.properties is a file with a single line: RUNSCOPE_TOKEN=<token>
9+
// e2e_test.properties is a file with a single line: WEBHOOK_AUTH_USERNAME=<token>
1010
def e2eTestPropertiesFile = file('e2e_test.properties')
1111
if (e2eTestPropertiesFile.exists()) {
1212
def props = new Properties()
1313
file(e2eTestPropertiesFile).withInputStream { stream -> props.load(stream) }
14-
RUNSCOPE_TOKEN = props.getProperty("RUNSCOPE_TOKEN")
14+
WEBHOOK_AUTH_USERNAME = props.getProperty("WEBHOOK_AUTH_USERNAME")
1515
RUN_E2E_TESTS = true
1616
}
1717

@@ -24,7 +24,7 @@ android {
2424
defaultConfig {
2525
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2626

27-
buildConfigField 'String', 'RUNSCOPE_TOKEN', "\"$RUNSCOPE_TOKEN\""
27+
buildConfigField 'String', 'WEBHOOK_AUTH_USERNAME', "\"$WEBHOOK_AUTH_USERNAME\""
2828
buildConfigField 'boolean', 'RUN_E2E_TESTS', "$RUN_E2E_TESTS"
2929
}
3030
}
@@ -44,4 +44,6 @@ dependencies {
4444
androidTestImplementation 'com.android.support.test:runner:1.0.2'
4545
androidTestImplementation 'com.android.support.test:rules:1.0.2'
4646
androidTestImplementation 'com.segment.backo:backo:1.0.0'
47+
48+
androidTestImplementation 'org.assertj:assertj-core:1.7.1'
4749
}

analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/E2ETest.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package com.segment.analytics;
22

33

4+
import static org.assertj.core.api.Assertions.assertThat;
45
import static org.junit.Assert.fail;
56

67
import android.support.test.rule.ActivityTestRule;
78
import android.support.test.runner.AndroidJUnit4;
8-
import com.segment.analytics.runscope.MessageResponse;
9-
import com.segment.analytics.runscope.MessagesResponse;
10-
import com.segment.analytics.runscope.RunscopeService;
9+
import com.segment.analytics.webhook.WebhookService;
1110
import com.segment.analytics.sample.MainActivity;
1211
import com.segment.analytics.sample.test.BuildConfig;
1312
import com.segment.backo.Backo;
1413
import java.io.IOException;
14+
import java.util.List;
1515
import java.util.UUID;
1616
import java.util.concurrent.TimeUnit;
17+
import okhttp3.Credentials;
1718
import okhttp3.Interceptor;
1819
import okhttp3.OkHttpClient;
1920
import org.junit.After;
@@ -50,43 +51,40 @@ public class E2ETest {
5051
* https://app.segment.com/segment-libraries/sources/analytics_android_e2e_test/overview
5152
*/
5253
private static final String SEGMENT_WRITE_KEY = "OAtgAHjkAD5MP31srDe9wiBjpvcXC8De";
53-
/**
54-
* Runscope bucket that is connect to the Segment project.
55-
* https://www.runscope.com/radar/uy22axz4sdb8
56-
*/
57-
private static final String RUNSCOPE_BUCKET = "uy22axz4sdb8";
58-
// Token to read data from the Runscope bucket.
59-
private static final String RUNSCOPE_TOKEN = BuildConfig.RUNSCOPE_TOKEN;
54+
/** Webhook bucket that is connected to the Segment project. */
55+
private static final String WEBHOOK_BUCKET = "android";
56+
/** Credentials to retrieve data from the webhook. */
57+
private static final String WEBHOOK_AUTH_USERNAME = BuildConfig.WEBHOOK_AUTH_USERNAME;
6058

6159
private static final Backo BACKO = Backo.builder()
6260
.base(TimeUnit.SECONDS, 1)
6361
.cap(TimeUnit.SECONDS, 5)
6462
.build();
6563

6664
private Analytics analytics;
67-
private RunscopeService runscopeService;
65+
private WebhookService webhookService;
6866

6967
@Before
7068
public void setup() {
7169
analytics = new Analytics.Builder(activityActivityTestRule.getActivity(), SEGMENT_WRITE_KEY)
7270
.build();
7371

74-
runscopeService = new Retrofit.Builder()
75-
.baseUrl("https://api.runscope.com")
72+
webhookService = new Retrofit.Builder()
73+
.baseUrl("https://webhook-e2e.segment.com")
7674
.addConverterFactory(MoshiConverterFactory.create())
7775
.client(new OkHttpClient.Builder()
7876
.addNetworkInterceptor(new Interceptor() {
7977
@Override
8078
public okhttp3.Response intercept(Chain chain) throws IOException {
8179
return chain.proceed(chain.request()
8280
.newBuilder()
83-
.addHeader("Authorization", "Bearer " + RUNSCOPE_TOKEN)
81+
.addHeader("Authorization", Credentials.basic(WEBHOOK_AUTH_USERNAME, ""))
8482
.build());
8583
}
8684
})
8785
.build())
8886
.build()
89-
.create(RunscopeService.class);
87+
.create(WebhookService.class);
9088
}
9189

9290
@After
@@ -146,21 +144,19 @@ private void assertMessageReceivedByWebhook(String id) {
146144
}
147145

148146
/**
149-
* Returns {@code true} if a message with the provided ID is found in Runscope.
147+
* Returns {@code true} if a message with the provided ID is found in the webhook.
150148
*/
151149
@SuppressWarnings("ConstantConditions")
152150
private boolean hasMatchingRequest(String id) throws IOException {
153-
Response<MessagesResponse> messagesResponse = runscopeService
154-
.messages(RUNSCOPE_BUCKET)
151+
Response<List<String>> messagesResponse = webhookService
152+
.messages(WEBHOOK_BUCKET, 500)
155153
.execute();
156154

157-
for (MessagesResponse.Message message : messagesResponse.body().data) {
158-
Response<MessageResponse> messageResponse = runscopeService
159-
.message(RUNSCOPE_BUCKET, message.uuid)
160-
.execute();
155+
assertThat(messagesResponse.code()).isEqualTo(200);
161156

157+
for (String message : messagesResponse.body()) {
162158
// TODO: Deserialize into Segment message and check against properties.
163-
if (messageResponse.body().data.request.body.contains(id)) {
159+
if (message.contains(id)) {
164160
return true;
165161
}
166162
}

analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/runscope/MessageResponse.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/runscope/MessagesResponse.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

analytics-samples/analytics-sample/src/androidTest/java/com/segment/analytics/runscope/RunscopeService.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.segment.analytics.webhook;
2+
3+
import java.util.List;
4+
import retrofit2.Call;
5+
import retrofit2.http.GET;
6+
import retrofit2.http.Path;
7+
import retrofit2.http.Query;
8+
9+
public interface WebhookService {
10+
@GET("buckets/{bucket}")
11+
Call<List<String>> messages(@Path("bucket") String bucket, @Query("limit") int limit);
12+
}

0 commit comments

Comments
 (0)