Skip to content

Commit f214887

Browse files
Merge pull request #49 from Tinder/fix_init
GitQuery 3.0.5 - initConfig to throw IllegalArgumentException when includeGlobs is empty
2 parents 9c9bf4f + a767824 commit f214887

File tree

7 files changed

+136
-4
lines changed

7 files changed

+136
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ All notable changes to this library will be documented in this file.
33

44
Version in this change log adheres to [Semantic Versioning](http://semver.org/).
55

6+
### 3.0.5 (2020-12-02) [#49](https://github.com/Tinder/GitQuery/pull/49) Init Config: Throw illegal arg exception when include globs is empty ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)
7+
68
### 3.0.4 (2020-12-01) [#48](https://github.com/Tinder/GitQuery/pull/48) Fix cli bug prefixing / to path ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)
79

810
### 3.0.3 (2020-12-01) [#48](https://github.com/Tinder/GitQuery/pull/48) Allow init-config to use includeGlobs in config ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)

core/src/main/kotlin/com/tinder/gitquery/core/GitQueryInit.kt

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ object GitQueryInit {
3838
) {
3939
this.verbose = verbose
4040
config.validate()
41+
require(config.initConfig.includeGlobs.isNotEmpty()) {
42+
"Failed to init config: includeGlobs is empty"
43+
}
4144

4245
val actualRepoDirectory = config.getActualRepoPath(buildDir)
4346

core/src/main/kotlin/com/tinder/gitquery/core/GitQueryVersion.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ package com.tinder.gitquery.core
44
* This file was generated by ./build-support/bin/write-version-class
55
*/
66

7-
const val GIT_QUERY_VERSION = "3.0.4"
7+
const val GIT_QUERY_VERSION = "3.0.5"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package com.tinder.gitquery.core
2+
3+
import com.tinder.gitquery.core.config.GitQueryConfig
4+
import com.tinder.gitquery.core.config.GitQueryConfigSchema
5+
import com.tinder.gitquery.core.config.GitQueryInitConfig
6+
import org.junit.After
7+
import org.junit.Before
8+
import org.junit.Rule
9+
import org.junit.Test
10+
import org.junit.rules.TemporaryFolder
11+
import java.io.File
12+
13+
class GitQueryInitTest {
14+
@get:Rule
15+
val testProjectDir = TemporaryFolder()
16+
17+
@Before
18+
fun setup() {
19+
testProjectDir.create()
20+
testProjectDir.apply {
21+
newFolder("gitquery-output")
22+
}
23+
}
24+
25+
@After
26+
fun tearDown() {
27+
testProjectDir.delete()
28+
}
29+
30+
@Test
31+
fun `initConfig - given missing remote, should fail`() {
32+
// When
33+
val actualError = kotlin.runCatching {
34+
GitQueryInit.initConfig(
35+
configFile = "${testProjectDir.root}/gitquery.yml",
36+
config = GitQueryConfig(
37+
schema = GitQueryConfigSchema(version = "1"),
38+
branch = "master",
39+
files = mapOf(
40+
"definitions" to mapOf("user.proto" to "42933446d0321958e8c12216d04b9f0c382ebf1b")
41+
),
42+
repoDir = "${testProjectDir.root}/tmp/remote",
43+
outputDir = "${testProjectDir.root}/gitquery-output"
44+
),
45+
buildDir = testProjectDir.root.path
46+
)
47+
}.exceptionOrNull()
48+
49+
// Then
50+
require(actualError is IllegalArgumentException)
51+
assert(actualError.message == "Parameter remote may not be a blank string ()")
52+
53+
assert(!File("${testProjectDir.root}/gitquery-output/definitions/user.proto").exists())
54+
assert(!File("${testProjectDir.root}/gitquery-output/README.md").exists())
55+
}
56+
57+
@Test
58+
fun `initConfig - given missing branch, should fail`() {
59+
// When
60+
val actualError = kotlin.runCatching {
61+
GitQueryInit.initConfig(
62+
configFile = "${testProjectDir.root}/gitquery.yml",
63+
config = GitQueryConfig(
64+
schema = GitQueryConfigSchema(version = "1"),
65+
remote = "https://github.com/aminghadersohi/ProtoExample.git",
66+
branch = "",
67+
repoDir = "${testProjectDir.root}/tmp/remote",
68+
outputDir = "${testProjectDir.root}/gitquery-output"
69+
),
70+
buildDir = testProjectDir.root.path
71+
)
72+
}.exceptionOrNull()
73+
74+
// Then
75+
require(actualError is IllegalArgumentException)
76+
assert(actualError.message == "Parameter branch may not be a blank string ()")
77+
78+
assert(!File("${testProjectDir.root}/gitquery-output/definitions/user.proto").exists())
79+
assert(!File("${testProjectDir.root}/gitquery-output/README.md").exists())
80+
}
81+
82+
@Test
83+
fun `initConfig - given empty includeGlobs, should fail`() {
84+
// When
85+
val actualError = kotlin.runCatching {
86+
GitQueryInit.initConfig(
87+
configFile = "${testProjectDir.root}/gitquery.yml",
88+
config = GitQueryConfig(
89+
schema = GitQueryConfigSchema(version = "1"),
90+
remote = "https://github.com/aminghadersohi/ProtoExample.git",
91+
branch = "master",
92+
repoDir = "${testProjectDir.root}/tmp/remote",
93+
outputDir = "${testProjectDir.root}/gitquery-output"
94+
),
95+
buildDir = testProjectDir.root.path
96+
)
97+
}.exceptionOrNull()
98+
99+
// Then
100+
require(actualError is IllegalArgumentException)
101+
assert(actualError.message == "Failed to init config: includeGlobs is empty")
102+
103+
assert(!File("${testProjectDir.root}/gitquery-output/definitions/user.proto").exists())
104+
assert(!File("${testProjectDir.root}/gitquery-output/README.md").exists())
105+
}
106+
107+
@Test
108+
fun `initConfig - given non-existent file, should create file`() {
109+
// When
110+
GitQueryInit.initConfig(
111+
configFile = "${testProjectDir.root}/gitquery.yml",
112+
config = GitQueryConfig(
113+
schema = GitQueryConfigSchema(version = "1"),
114+
remote = "https://github.com/aminghadersohi/ProtoExample.git",
115+
branch = "master",
116+
repoDir = "${testProjectDir.root}/tmp/remote",
117+
outputDir = "${testProjectDir.root}/gitquery-output",
118+
initConfig = GitQueryInitConfig(
119+
includeGlobs = listOf("**/*.proto")
120+
)
121+
),
122+
buildDir = testProjectDir.root.path
123+
)
124+
125+
assert(File("${testProjectDir.root}/gitquery.yml").exists())
126+
}
127+
}

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ org.gradle.daemon=true
77
org.gradle.parallel=true
88

99
GROUP=com.tinder.gitquery
10-
VERSION_NAME=3.0.4
10+
VERSION_NAME=3.0.5
1111

1212
POM_DESCRIPTION=A library for querying and syncing files in a remote git repo.
1313
POM_URL=https://github.com/Tinder/GitQuery

samples/protobuf-sync-code-gen/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.google.protobuf.gradle.protoc
99
plugins {
1010
application
1111
id("com.google.protobuf") version "0.8.13"
12-
id("com.tinder.gitquery") version "3.0.4"
12+
id("com.tinder.gitquery") version "3.0.5"
1313
java
1414
}
1515

samples/protobuf-sync-groovy-dsl/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("java")
3-
id("com.tinder.gitquery") version "3.0.4"
3+
id("com.tinder.gitquery") version "3.0.5"
44
}
55

66
def protoDir = "src/main/proto"

0 commit comments

Comments
 (0)