Skip to content

Commit

Permalink
feat: add Gradle DSL functions for deprecated tag forms of selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
uglyog committed Aug 2, 2022
1 parent fe643c9 commit f021ef1
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,36 @@ open class ConsumerVersionSelectorConfig {
fun environment(environment: String) {
selectors.add(ConsumerVersionSelectors.Environment(environment))
}

/**
* All versions with the specified tag
*/
@Deprecated("Tags are deprecated in favor of branches", ReplaceWith("branch"))
fun tag(name: String) {
selectors.add(ConsumerVersionSelectors.Tag(name))
}

/**
* The latest version for each consumer with the specified tag
*/
@Deprecated("Tags are deprecated in favor of branches", ReplaceWith("branch"))
fun latestTag(name: String) {
selectors.add(ConsumerVersionSelectors.LatestTag(name))
}

/**
* Generic selector.
*
* * With just the tag name, returns all versions with the specified tag.
* * With latest, returns the latest version for each consumer with the specified tag.
* * With a fallback tag, returns the latest version for each consumer with the specified tag, falling back to the
* fallbackTag if non is found with the specified tag.
* * With a consumer name, returns the latest version for a specified consumer with the specified tag.
* * With only latest, returns the latest version for each consumer. NOT RECOMMENDED as it suffers from race
* conditions when pacts are published from multiple branches.
*/
@Deprecated("Tags are deprecated in favor of branches", ReplaceWith("branch"))
fun selector(tagName: String?, latest: Boolean?, fallbackTag: String?, consumer: String?) {
selectors.add(ConsumerVersionSelectors.Selector(tagName, latest, consumer, fallbackTag))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package au.com.dius.pact.provider.gradle

import au.com.dius.pact.core.pactbroker.ConsumerVersionSelectors
import spock.lang.Specification
import spock.lang.Unroll

class ConsumerVersionSelectorConfigSpec extends Specification {
ConsumerVersionSelectorConfig config

def setup() {
config = new ConsumerVersionSelectorConfig()
}

def 'main branch selector'() {
when:
config.mainBranch()

then:
config.selectors == [ ConsumerVersionSelectors.MainBranch.INSTANCE ]
}

@Unroll
def 'branch selector'() {
when:
config.branch(name, consumer, fallback)

then:
config.selectors == [ selector ]

where:

name | consumer | fallback | selector
'test' | null | null | new ConsumerVersionSelectors.Branch('test')
'test' | 'con' | null | new ConsumerVersionSelectors.Branch('test', 'con')
'test' | null | 'back' | new ConsumerVersionSelectors.Branch('test', null, 'back')
'test' | 'con' | 'back' | new ConsumerVersionSelectors.Branch('test', 'con', 'back')
}

def 'deployed or released selector'() {
when:
config.deployedOrReleased()

then:
config.selectors == [ ConsumerVersionSelectors.DeployedOrReleased.INSTANCE ]
}

def 'matching branch selector'() {
when:
config.matchingBranch()

then:
config.selectors == [ ConsumerVersionSelectors.MatchingBranch.INSTANCE ]
}

def 'deployed to selector'() {
when:
config.deployedTo('env')

then:
config.selectors == [ new ConsumerVersionSelectors.DeployedTo('env') ]
}

def 'released to selector'() {
when:
config.releasedTo('env')

then:
config.selectors == [ new ConsumerVersionSelectors.ReleasedTo('env') ]
}

def 'environment selector'() {
when:
config.environment('env')

then:
config.selectors == [ new ConsumerVersionSelectors.Environment('env') ]
}

def 'tag selector'() {
when:
config.tag('t')

then:
config.selectors == [ new ConsumerVersionSelectors.Tag('t') ]
}

def 'latest tag selector'() {
when:
config.latestTag('t')

then:
config.selectors == [ new ConsumerVersionSelectors.LatestTag('t') ]
}

@Unroll
def 'generic selector'() {
when:
config.selector(tag, latest, fallback, consumer)

then:
config.selectors == [ selector ]

where:

tag | latest | consumer | fallback | selector
'test' | null | null | null | new ConsumerVersionSelectors.Selector('test')
'test' | true | null | null | new ConsumerVersionSelectors.Selector('test', true)
'test' | true | null | 'back' | new ConsumerVersionSelectors.Selector('test', true, null, 'back')
'test' | true | 'con' | 'back' | new ConsumerVersionSelectors.Selector('test', true, 'con', 'back')
null | true | null | null | new ConsumerVersionSelectors.Selector(null, true, null, null)
}
}

0 comments on commit f021ef1

Please sign in to comment.