spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

Maven plugin generateTests goal should have an option to fail on bad contracts

Open tn185070 opened this issue 4 years ago • 9 comments

Is your feature request related to a problem? Please describe. We utilize contract tests to test our projects and rely on a passing build to signify that our project is working. However we have seen that passing contract tests is not necessarily a sure indicator of a project's status. If a contract definition is bad then the generateTests goal of the spring-cloud-contract-maven-plugin will just skip generating tests for that contract, and continue to generate tests for other contracts, then our tests will run the generated tests, succeed, and then we will not know that tests were not run for the cases covered by the bad contracts.

Describe the solution you'd like

We would like the spring-cloud-contract-maven-plugin to have an option to fail the maven build if a contract cannot be converted to a test.

Describe alternatives you've considered Doing maven log verification in a jenkinsfile or using the enforcer plugin.

Additional context Can provide sample project if required.

tn185070 avatar Jun 22 '21 01:06 tn185070

we need this option in gradle to)

VovkaSOL avatar Jul 29 '21 13:07 VovkaSOL

I found this very bad solution, which can stop and fail build when contracs not generated, may be someone need it. parsing stdout)

def stdoutLogger = [
        onOutput: {
            if(String.valueOf(it).contains("Error Processing yaml")){
                project.ext.set("contracts_fail", true)
            }
        }
] as StandardOutputListener
gradle.taskGraph.whenReady { taskGraph ->
    project.ext.set("contracts_fail", false)
    taskGraph.allTasks.each { Task t ->
        if (t.name == 'generateContractTests') {
            t.doFirst {
                logging.addStandardOutputListener(stdoutLogger)
            }
        }
    }
}

project.gradle.taskGraph.beforeTask { task ->
        if(String.valueOf(task.name).contains("compileTestJava")){
            if(project.ext.getProperty("contracts_fail")==true){
                throw new GradleException('Generating contract tests fail=BUILD FAIL!!!')
            }
        }
}

VovkaSOL avatar Jul 31 '21 13:07 VovkaSOL

Any progres ?

marwin1991 avatar Nov 07 '22 12:11 marwin1991

Failing the build if some of the contracts cannot be processed should be the default behavior, IMHO.

g-fresh avatar Mar 30 '23 07:03 g-fresh

So currently we are iterating over a list of contract converters and some of them are failing (e.g. pact one would fail because JSON Wiremock stub would be parsed by the pact parser). We wouldn't want to fail the build there. OTOH maybe the problem is with how we wrote some logic in the converter in the first place.

marcingrzejszczak avatar Mar 30 '23 09:03 marcingrzejszczak

Any news on this? :)

os-cas avatar Oct 25 '23 07:10 os-cas