Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow Raven to be configured from the SENTRY_DSN environment variable

  • Loading branch information...
commit 7c76f06de151c9e71abb26800d2bb39d4fcc9240 1 parent 62929ad
@dcramer dcramer authored
View
39 pom.xml
@@ -33,6 +33,12 @@
<version>1.2.16</version>
</dependency>
<dependency>
+ <groupId>com.googlecode.jmockit</groupId>
+ <artifactId>jmockit</artifactId>
+ <version>0.999.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
@@ -78,6 +84,39 @@
</executions>
</plugin>
</plugins>
+
+ <resources>
+ <resource>
+ <directory>${basedir}/src/main/java</directory>
+ <includes>
+ <include>**/*.json</include>
+ <include>**/*.yml</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*.*</include>
+ </includes>
+ </resource>
+ </resources>
+
+ <testResources>
+ <testResource>
+ <directory>${basedir}/src/test/java</directory>
+ <includes>
+ <include>**/*.json</include>
+ <include>**/*.yml</include>
+ <include>**/*.txt</include>
+ </includes>
+ </testResource>
+ <testResource>
+ <directory>${basedir}/src/test/resources</directory>
+ <includes>
+ <include>**/*.*</include>
+ </includes>
+ </testResource>
+ </testResources>
</build>
</project>
View
8 src/main/java/net/kencochrane/sentry/RavenClient.java
@@ -23,6 +23,14 @@
private RavenConfig config;
private String sentryDSN;
+ public RavenClient() {
+ this.sentryDSN = System.getenv("SENTRY_DSN");
+ if (this.sentryDSN == null || this.sentryDSN.length() == 0) {
+ throw new RuntimeException("You must provide a DSN to RavenClient");
+ }
+ this.config = new RavenConfig(this.sentryDSN);
+ }
+
public RavenClient(String sentryDSN) {
this.sentryDSN = sentryDSN;
this.config = new RavenConfig(sentryDSN);
View
29 src/test/java/net/kencochrane/sentry/SentryClientTest.java
@@ -0,0 +1,29 @@
+package net.kencochrane.sentry;
+
+import mockit.Mocked;
+import mockit.Expectations;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class SentryClientTest {
+ @Test
+ public void testConfigureFromDSN() {
+ RavenClient client = new RavenClient("http://public:secret@example.com/path/1");
+ assertEquals(client.getSentryDSN(), "http://public:secret@example.com/path/1");
+ }
+
+ @Test
+ public void testConfigureFromEnvironment() {
+ new Expectations()
+ {
+ @Mocked("getenv") System mockedSystem;
+
+ {
+ System.getenv("SENTRY_DSN"); returns("http://public:secret@example.com/path/1");
+ }
+ };
+ RavenClient client = new RavenClient();
+ assertEquals(client.getSentryDSN(), "http://public:secret@example.com/path/1");
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.