Skip to content

Commit

Permalink
fix markdown update on empty schema
Browse files Browse the repository at this point in the history
  • Loading branch information
forozco committed Aug 17, 2020
1 parent fb34baf commit 0f7e3a6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public final void generate() throws IOException {
Map<String, List<MetricSchema>> schemas =
ObjectMappers.mapper.readValue(manifest, new TypeReference<Map<String, List<MetricSchema>>>() {});
if (schemas.isEmpty()) {
if (markdown.exists()) {
markdown.delete();
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.palantir.metric.schema.gradle
import nebula.test.IntegrationSpec

class GenerateMetricMarkdownIntegrationSpec extends IntegrationSpec {
public static final String METRICS = """
private static final String METRICS = """
namespaces:
server:
docs: General web server metrics.
Expand All @@ -34,6 +34,18 @@ class GenerateMetricMarkdownIntegrationSpec extends IntegrationSpec {
type: gauge
docs: A gauge of the ratio of active workers to the number of workers.
""".stripIndent()
private static final String SHORT_METRICS = """
namespaces:
server:
docs: General web server metrics.
metrics:
response.size:
type: histogram
tags:
- service-name
- endpoint
docs: A histogram of the number of bytes written into the response.
""".stripIndent()

void setup() {
buildFile << """
Expand All @@ -53,33 +65,25 @@ class GenerateMetricMarkdownIntegrationSpec extends IntegrationSpec {
}
}
""".stripIndent()
file('src/main/metrics/metrics.yml') << METRICS
}

def 'generate markdown'() {
when:
file('src/main/metrics/metrics.yml') << METRICS

then:
expect:
def result = runTasksSuccessfully('--write-locks')
result.wasExecuted(':generateMetricsMarkdown')
fileExists("metrics.md")
}

def 'fails if markdown does not exist'() {
when:
file('src/main/metrics/metrics.yml') << METRICS

then:
expect:
def result = runTasksWithFailure(':check')
result.wasExecuted(':checkMetricsMarkdown')
result.standardError.contains("metrics.md does not exist")
}

def 'fails if markdown is out of date'() {
when:
file('src/main/metrics/metrics.yml') << METRICS

then:
expect:
def result1 = runTasksSuccessfully('--write-locks')
result1.wasExecuted(':generateMetricsMarkdown')
fileExists("metrics.md")
Expand All @@ -88,4 +92,38 @@ class GenerateMetricMarkdownIntegrationSpec extends IntegrationSpec {
def result2 = runTasksWithFailure(':check')
result2.standardError.contains("metrics.md is out of date")
}

def 'markdown is cleaned up correctly'() {
when:
def result1 = runTasksSuccessfully('--write-locks')

then:
result1.wasExecuted(':generateMetricsMarkdown')
fileExists("metrics.md")

when:
file('src/main/metrics/metrics.yml').delete()

then:
def result2 = runTasksSuccessfully('--write-locks')
result2.wasExecuted(':generateMetricsMarkdown')
!file('metrics.md')
}

def 'markdown is cached correctly'() {
when:
def result1 = runTasksSuccessfully('--write-locks')

then:
result1.wasExecuted(':generateMetricsMarkdown')
fileExists("metrics.md")

when:
file('src/main/metrics/metrics.yml').text = SHORT_METRICS;

then:
def result2 = runTasksSuccessfully('--write-locks')
result2.wasExecuted(':generateMetricsMarkdown')
!fileExists('metrics.md')
}
}

0 comments on commit 0f7e3a6

Please sign in to comment.