-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ArtisanCloud/develop
feature - refact(map): MergeHashMap and MergeStringMap with test - refact(map): ReplaceHashMap and replaceStringMap with test
- Loading branch information
Showing
10 changed files
with
288 additions
and
46 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
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,57 @@ | ||
package logger | ||
|
||
import ( | ||
"github.com/ArtisanCloud/PowerLibs/object" | ||
"net/http" | ||
"os" | ||
"testing" | ||
) | ||
|
||
var strArtisanCloudPath = "/var/log/ArtisanCloud/PowerLibs" | ||
var strOutputPath = strArtisanCloudPath + "/output.log" | ||
var strErrorPath = strArtisanCloudPath + "/errors.log" | ||
|
||
func init() { | ||
err := initLogPath(strArtisanCloudPath, strOutputPath, strErrorPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func Test_Log_Info(t *testing.T) { | ||
driver := "zap" | ||
logger, err := NewLogger(driver, &object.HashMap{ | ||
"env": "test", | ||
"outputPath": strOutputPath, | ||
"errorPath": strErrorPath, | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
logger.Info("test info", "app response", &http.Response{}) | ||
|
||
} | ||
|
||
func initLogPath(path string, files ...string) (err error) { | ||
if _, err = os.Stat(path); os.IsNotExist(err) { | ||
err = os.MkdirAll(path, os.ModePerm) | ||
if err != nil { | ||
return err | ||
} | ||
} else if os.IsPermission(err) { | ||
return err | ||
} | ||
|
||
for _, fileName := range files { | ||
if _, err = os.Stat(fileName); os.IsNotExist(err) { | ||
_, err = os.Create(fileName) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return err | ||
|
||
} |
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,78 @@ | ||
package object | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_MergeHashMap(t *testing.T) { | ||
|
||
base := &HashMap{ | ||
"key1": 123, | ||
"key2": "456", | ||
"key3": "", | ||
"key4": nil, | ||
"key5": &StringMap{}, | ||
"key6": &HashMap{}, | ||
} | ||
|
||
toMap := &HashMap{ | ||
"key2": "", | ||
"key3": "123", | ||
"key4": &HashMap{}, | ||
"key5": nil, | ||
"key6": &StringMap{}, | ||
} | ||
|
||
toMap = MergeHashMap(toMap, base) | ||
|
||
assert.EqualValues(t, &HashMap{ | ||
"key1": 123, | ||
"key2": "456", | ||
"key3": "123", | ||
"key4": &HashMap{}, | ||
"key5": &StringMap{}, | ||
"key6": &StringMap{}, | ||
}, toMap) | ||
|
||
} | ||
|
||
func Test_ReplaceHashMapRecursive(t *testing.T) { | ||
|
||
base := &HashMap{ | ||
"key1": 123, | ||
"key2": "456", | ||
"key3": "789", | ||
"key4": nil, | ||
"key5": map[string]int{}, | ||
"key6": &map[string]float32{}, | ||
} | ||
|
||
base2 := &HashMap{ | ||
"key1": 456, | ||
"key2": "base456", | ||
"key3": "", | ||
"key4": nil, | ||
"key5": &StringMap{}, | ||
} | ||
|
||
toMap := &HashMap{ | ||
"key2": "", | ||
"key3": "123", | ||
"key4": &HashMap{}, | ||
"key5": nil, | ||
"key6": &StringMap{}, | ||
} | ||
|
||
toMap = ReplaceHashMapRecursive(toMap, base, base2) | ||
|
||
assert.EqualValues(t, &HashMap{ | ||
"key1": 456, | ||
"key2": "base456", | ||
"key3": "", | ||
"key4": nil, | ||
"key5": &StringMap{}, | ||
"key6": &map[string]float32{}, | ||
}, toMap) | ||
|
||
} |
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
Oops, something went wrong.