-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #1121 from yquansah/yq-override-json
feat: add definition for overridable json engine
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package utils | ||
|
||
// JSONMarshal is the standard definition of representing a Go structure in | ||
// json format | ||
type JSONMarshal func(interface{}) ([]byte, error) |
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,26 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
) | ||
|
||
func TestDefaultJSONEncoder(t *testing.T) { | ||
type SampleStructure struct { | ||
ImportantString string `json:"important_string"` | ||
} | ||
|
||
var ( | ||
sampleStructure = &SampleStructure{ | ||
ImportantString: "Hello World", | ||
} | ||
importantString = `{"important_string":"Hello World"}` | ||
|
||
jsonEncoder JSONMarshal = json.Marshal | ||
) | ||
|
||
raw, err := jsonEncoder(sampleStructure) | ||
AssertEqual(t, err, nil) | ||
|
||
AssertEqual(t, string(raw), importantString) | ||
} |