This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.pg | ||
|
||
import weaver._ | ||
import io.circe.literal._ | ||
import io.pg.config.ProjectConfig | ||
import io.pg.config.ProjectConfigReader | ||
import io.pg.gitlab.webhook.Project | ||
import io.pg.config.Rule | ||
import io.pg.config.Action | ||
import io.pg.config.Matcher | ||
import io.pg.config.TextMatcher | ||
import io.circe.syntax._ | ||
|
||
object ProjectConfigFormatTest extends FunSuite { | ||
|
||
val asJSON = json"""{ | ||
"rules": [ | ||
{ | ||
"action": "Merge", | ||
"matcher": { | ||
"kind": "Many", | ||
"values": [ | ||
{ | ||
"email": { | ||
"kind": "Equals", | ||
"value": "[email protected]" | ||
}, | ||
"kind": "Author" | ||
}, | ||
{ | ||
"kind": "Description", | ||
"text": { | ||
"kind": "Matches", | ||
"regex": ".*labels:.*semver-patch.*" | ||
} | ||
}, | ||
{ | ||
"kind": "PipelineStatus", | ||
"status": "success" | ||
} | ||
] | ||
}, | ||
"name": "Scala Steward" | ||
} | ||
] | ||
} | ||
""" | ||
|
||
val decoded = ProjectConfig( | ||
rules = List( | ||
Rule( | ||
name = "Scala Steward", | ||
action = Action.Merge, | ||
matcher = Matcher.Many( | ||
List( | ||
Matcher.Author(TextMatcher.Equals("[email protected]")), | ||
Matcher.Description(TextMatcher.Matches(".*labels:.*semver-patch.*".r)), | ||
Matcher.PipelineStatus("success") | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
test("Example config can be decoded") { | ||
val actual = asJSON.as[ProjectConfig] | ||
assert(actual == Right(decoded)) | ||
} | ||
test("Example config can be encoded") { | ||
val actual = decoded.asJson | ||
assert.eql(actual, asJSON) | ||
} | ||
} |