Fix the dependency issue (#231)
This commit is contained in:
34
vendor/github.com/hyperhq/hypercli/pkg/jsonlog/jsonlog_marshalling_test.go
generated
vendored
34
vendor/github.com/hyperhq/hypercli/pkg/jsonlog/jsonlog_marshalling_test.go
generated
vendored
@@ -1,34 +0,0 @@
|
||||
package jsonlog
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJSONLogMarshalJSON(t *testing.T) {
|
||||
logs := map[JSONLog]string{
|
||||
{Log: `"A log line with \\"`}: `^{\"log\":\"\\\"A log line with \\\\\\\\\\\"\",\"time\":\".{20,}\"}$`,
|
||||
{Log: "A log line"}: `^{\"log\":\"A log line\",\"time\":\".{20,}\"}$`,
|
||||
{Log: "A log line with \r"}: `^{\"log\":\"A log line with \\r\",\"time\":\".{20,}\"}$`,
|
||||
{Log: "A log line with & < >"}: `^{\"log\":\"A log line with \\u0026 \\u003c \\u003e\",\"time\":\".{20,}\"}$`,
|
||||
{Log: "A log line with utf8 : 🚀 ψ ω β"}: `^{\"log\":\"A log line with utf8 : 🚀 ψ ω β\",\"time\":\".{20,}\"}$`,
|
||||
{Stream: "stdout"}: `^{\"stream\":\"stdout\",\"time\":\".{20,}\"}$`,
|
||||
{}: `^{\"time\":\".{20,}\"}$`,
|
||||
// These ones are a little weird
|
||||
{Log: "\u2028 \u2029"}: `^{\"log\":\"\\u2028 \\u2029\",\"time\":\".{20,}\"}$`,
|
||||
{Log: string([]byte{0xaF})}: `^{\"log\":\"\\ufffd\",\"time\":\".{20,}\"}$`,
|
||||
{Log: string([]byte{0x7F})}: `^{\"log\":\"\x7f\",\"time\":\".{20,}\"}$`,
|
||||
}
|
||||
for jsonLog, expression := range logs {
|
||||
data, err := jsonLog.MarshalJSON()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res := string(data)
|
||||
t.Logf("Result of WriteLog: %q", res)
|
||||
logRe := regexp.MustCompile(expression)
|
||||
if !logRe.MatchString(res) {
|
||||
t.Fatalf("Log line not in expected format [%v]: %q", expression, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
39
vendor/github.com/hyperhq/hypercli/pkg/jsonlog/jsonlogbytes_test.go
generated
vendored
39
vendor/github.com/hyperhq/hypercli/pkg/jsonlog/jsonlogbytes_test.go
generated
vendored
@@ -1,39 +0,0 @@
|
||||
package jsonlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJSONLogsMarshalJSONBuf(t *testing.T) {
|
||||
logs := map[*JSONLogs]string{
|
||||
{Log: []byte(`"A log line with \\"`)}: `^{\"log\":\"\\\"A log line with \\\\\\\\\\\"\",\"time\":}$`,
|
||||
{Log: []byte("A log line")}: `^{\"log\":\"A log line\",\"time\":}$`,
|
||||
{Log: []byte("A log line with \r")}: `^{\"log\":\"A log line with \\r\",\"time\":}$`,
|
||||
{Log: []byte("A log line with & < >")}: `^{\"log\":\"A log line with \\u0026 \\u003c \\u003e\",\"time\":}$`,
|
||||
{Log: []byte("A log line with utf8 : 🚀 ψ ω β")}: `^{\"log\":\"A log line with utf8 : 🚀 ψ ω β\",\"time\":}$`,
|
||||
{Stream: "stdout"}: `^{\"stream\":\"stdout\",\"time\":}$`,
|
||||
{Stream: "stdout", Log: []byte("A log line")}: `^{\"log\":\"A log line\",\"stream\":\"stdout\",\"time\":}$`,
|
||||
{Created: "time"}: `^{\"time\":time}$`,
|
||||
{}: `^{\"time\":}$`,
|
||||
// These ones are a little weird
|
||||
{Log: []byte("\u2028 \u2029")}: `^{\"log\":\"\\u2028 \\u2029\",\"time\":}$`,
|
||||
{Log: []byte{0xaF}}: `^{\"log\":\"\\ufffd\",\"time\":}$`,
|
||||
{Log: []byte{0x7F}}: `^{\"log\":\"\x7f\",\"time\":}$`,
|
||||
// with raw attributes
|
||||
{Log: []byte("A log line"), RawAttrs: []byte(`{"hello":"world","value":1234}`)}: `^{\"log\":\"A log line\",\"attrs\":{\"hello\":\"world\",\"value\":1234},\"time\":}$`,
|
||||
}
|
||||
for jsonLog, expression := range logs {
|
||||
var buf bytes.Buffer
|
||||
if err := jsonLog.MarshalJSONBuf(&buf); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res := buf.String()
|
||||
t.Logf("Result of WriteLog: %q", res)
|
||||
logRe := regexp.MustCompile(expression)
|
||||
if !logRe.MatchString(res) {
|
||||
t.Fatalf("Log line not in expected format [%v]: %q", expression, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
47
vendor/github.com/hyperhq/hypercli/pkg/jsonlog/time_marshalling_test.go
generated
vendored
47
vendor/github.com/hyperhq/hypercli/pkg/jsonlog/time_marshalling_test.go
generated
vendored
@@ -1,47 +0,0 @@
|
||||
package jsonlog
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Testing to ensure 'year' fields is between 0 and 9999
|
||||
func TestFastTimeMarshalJSONWithInvalidDate(t *testing.T) {
|
||||
aTime := time.Date(-1, 1, 1, 0, 0, 0, 0, time.Local)
|
||||
json, err := FastTimeMarshalJSON(aTime)
|
||||
if err == nil {
|
||||
t.Fatalf("FastTimeMarshalJSON should throw an error, but was '%v'", json)
|
||||
}
|
||||
anotherTime := time.Date(10000, 1, 1, 0, 0, 0, 0, time.Local)
|
||||
json, err = FastTimeMarshalJSON(anotherTime)
|
||||
if err == nil {
|
||||
t.Fatalf("FastTimeMarshalJSON should throw an error, but was '%v'", json)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFastTimeMarshalJSON(t *testing.T) {
|
||||
aTime := time.Date(2015, 5, 29, 11, 1, 2, 3, time.UTC)
|
||||
json, err := FastTimeMarshalJSON(aTime)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := "\"2015-05-29T11:01:02.000000003Z\""
|
||||
if json != expected {
|
||||
t.Fatalf("Expected %v, got %v", expected, json)
|
||||
}
|
||||
|
||||
location, err := time.LoadLocation("Europe/Paris")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
aTime = time.Date(2015, 5, 29, 11, 1, 2, 3, location)
|
||||
json, err = FastTimeMarshalJSON(aTime)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected = "\"2015-05-29T11:01:02.000000003+02:00\""
|
||||
if json != expected {
|
||||
t.Fatalf("Expected %v, got %v", expected, json)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user