Repository: yorkie-team/yorkie
Pull request #45 (2020-04-09 08:50:04)

Add TestNewConfigFromFile
<!--  Thanks for sending a pull request! -->

**What type of PR is this?**
> Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespace from that line:
>
> /kind api-change
> /kind bug
> /kind cleanup
> /kind deprecation
> /kind design
> /kind documentation
> /kind failing-test
> /kind feature

/kind test

**What this PR does / why we need it**:
Added Testing NewConfigFromFile function

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note

```

**Additional documentation**:

<!--
This section can be blank if this pull request does not require a release note.

Please use the following format for linking documentation:
- [Usage]: <link>
- [Other doc]: <link>
-->
```docs

```



Patch:
diff --git a/yorkie/config.sample.json b/yorkie/config.sample.json
new file mode 100644
index 00000000..29f0ecdb
--- /dev/null
+++ b/yorkie/config.sample.json
@@ -0,0 +1,16 @@
+{
+    "RPC": {
+        "Port": 9090,
+        "CertFile": "",
+        "KeyFile": ""
+    },
+    "Mongo": {
+        "ConnectionTimeoutSec": 5,
+        "ConnectionURI": "mongodb://localhost:27017",
+        "YorkieDatabase": "yorkie-meta",
+        "PingTimeoutSec": 5
+    },
+    "Backend": {
+        "SnapshotThreshold": 500
+    }
+}


Test patch:
diff --git a/yorkie/config_test.go b/yorkie/config_test.go
new file mode 100644
index 00000000..a9742f6d
--- /dev/null
+++ b/yorkie/config_test.go
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2020 The Yorkie Authors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package yorkie_test
+
+import (
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/yorkie-team/yorkie/yorkie"
+)
+
+func TestNewConfigFromFile(t *testing.T) {
+	filePath := "config.sample.json"
+	conf, err := yorkie.NewConfigFromFile(filePath)
+	assert.NoError(t, err)
+
+	assert.Equal(t, conf.RPC.Port, yorkie.DefaultRPCPort)
+	assert.Equal(t, conf.RPC.CertFile, "")
+	assert.Equal(t, conf.RPC.KeyFile, "")
+	assert.Equal(t, conf.Mongo.ConnectionTimeoutSec, time.Duration(yorkie.DefaultMongoConnectionTimeoutSec))
+	assert.Equal(t, conf.Mongo.ConnectionURI, yorkie.DefaultMongoConnectionURI)
+	assert.Equal(t, conf.Mongo.YorkieDatabase, yorkie.DefaultMongoYorkieDatabase)
+	assert.Equal(t, conf.Mongo.PingTimeoutSec, time.Duration(yorkie.DefaultMongoPingTimeoutSec))
+	assert.Equal(t, conf.Backend.SnapshotThreshold, uint64(yorkie.DefaultSnapshotThreshold))
+}