matrixji commented on code in PR #2106:
URL: https://github.com/apache/incubator-devlake/pull/2106#discussion_r891821617


##########
config/config_test.go:
##########
@@ -18,57 +18,42 @@ limitations under the License.
 package config
 
 import (
-       "os"
-       "testing"
-
-       "github.com/spf13/viper"
+       "github.com/sirupsen/logrus"
+       "github.com/spf13/afero"
        "github.com/stretchr/testify/assert"
+       "testing"
 )
 
-func TestReadAndWriteToConfig(t *testing.T) {
+func TestReadConfig(t *testing.T) {
+       DbUrl := 
"mysql://merico:merico@mysql:3306/lake?charset=utf8mb4&parseTime=True"
        v := GetConfig()
        currentDbUrl := v.GetString("DB_URL")
-       newDbUrl := "ThisIsATest"
-       assert.Equal(t, currentDbUrl != newDbUrl, true)
-       v.Set("DB_URL", newDbUrl)
-       err := v.WriteConfig()
-       assert.Equal(t, err == nil, true)
-       nowDbUrl := v.GetString("DB_URL")
-       assert.Equal(t, nowDbUrl == newDbUrl, true)
-       // Reset back to current
-       v.Set("DB_URL", currentDbUrl)
-       err = v.WriteConfig()
-       assert.Equal(t, err == nil, true)
+       logrus.Infof("current db url: %s\n", currentDbUrl)
+       assert.Equal(t, currentDbUrl == DbUrl, true)
 }
 
-func TestGetEnvPath(t *testing.T) {
-       os.Unsetenv("ENV_PATH")
-       assert.Equal(t, getEnvPath(), ".env")
-       os.Setenv("ENV_PATH", "/foo/bar/config.env")
-       assert.Equal(t, getEnvPath(), "/foo/bar/config.env")
+func TestWriteConfig(t *testing.T) {
+       filename := ".env"
+       v := GetConfig()
+       newDbUrl := 
"mysql://merico:merico@mysql:3307/lake?charset=utf8mb4&parseTime=True"
+       v.Set("DB_URL", newDbUrl)
+       fs := afero.NewOsFs()
+       file, _ := fs.Create(filename)
+       defer file.Close()
+       _ = WriteConfigAs(v, filename)
+       isEmpty, _ := afero.IsEmpty(fs, filename)
+       assert.False(t, isEmpty)
+       err := fs.Remove(filename)
+       assert.Equal(t, err == nil, true)
 }
 
-func TestWriteConfigToEnvPath(t *testing.T) {

Review Comment:
   We'd better not remove the testing code, but adapt it to work for the new 
implementations.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to