Repository: uber-go/zap
File: zapcore/encoder_test.go (Go)

Code before:

	for _, tt := range tests {
		cfg := EncoderConfig{}
		require.NoError(t, yaml.Unmarshal([]byte(tt.yamlDoc), &cfg), "Unexpected error unmarshaling %q.", tt.yamlDoc)
		require.NotNil(t, cfg.EncodeTime, "Unmashalled timeEncoder is nil for %q.", tt.yamlDoc)
		assertAppended(
			t,
			tt.expected,
			func(arr ArrayEncoder) { cfg.EncodeTime(moment, arr) },
			"Unexpected output serializing %v with %q.", moment, tt.yamlDoc,
		)
	}
}

func TestTimeEncodersWrongYAML(t *testing.T) {
	tests := []string{
		"timeEncoder: [1, 2, 3]", // wrong type
		"timeEncoder: {foo:bar",  // broken yaml
	}
	for _, tt := range tests {
		cfg := EncoderConfig{}
		assert.Error(t, yaml.Unmarshal([]byte(tt), &cfg), "Expected unmarshaling %q to become error, but not.", tt)
	}
}

func TestTimeEncodersParseFromJson(t *testing.T) {
	moment := time.Unix(100, 50005000).UTC()
	tests := []struct {
		jsonDoc  string
		expected interface{} // output of serializing moment
	}{
		{`{"timeEncoder": "iso8601"}`, "1970-01-01T00:01:40.050Z"},
		{`{"timeEncoder": {"layout": "06/01/02 03:04pm"}}`, "70/01/01 12:01am"},
	}

	for _, tt := range tests {
		cfg := EncoderConfig{}
		require.NoError(t, json.Unmarshal([]byte(tt.jsonDoc), &cfg), "Unexpected error unmarshaling %q.", tt.jsonDoc)
		require.NotNil(t, cfg.EncodeTime, "Unmashalled timeEncoder is nil for %q.", tt.jsonDoc)
		assertAppended(
			t,
			tt.expected,
			func(arr ArrayEncoder) { cfg.EncodeTime(moment, arr) },
			"Unexpected output serializing %v with %q.", moment, tt.jsonDoc,
		)
	}
}

func TestDurationEncoders(t *testing.T) {
	elapsed := time.Second + 500*time.Nanosecond
	tests := []struct {

Review comment (suggestion):
s/Json/JSON
```suggestion
func TestTimeEncodersParseFromJSON(t *testing.T) {
```

Code after:
	for _, tt := range tests {
		cfg := EncoderConfig{}
		require.NoError(t, yaml.Unmarshal([]byte(tt.yamlDoc), &cfg), "Unexpected error unmarshaling %q.", tt.yamlDoc)
		require.NotNil(t, cfg.EncodeTime, "Unmashalled timeEncoder is nil for %q.", tt.yamlDoc)
		assertAppended(
			t,
			tt.expected,
			func(arr ArrayEncoder) { cfg.EncodeTime(moment, arr) },
			"Unexpected output serializing %v with %q.", moment, tt.yamlDoc,
		)
	}
}

func TestTimeEncodersWrongYAML(t *testing.T) {
	tests := []string{
		"timeEncoder: [1, 2, 3]", // wrong type
		"timeEncoder: {foo:bar",  // broken yaml
	}
	for _, tt := range tests {
		cfg := EncoderConfig{}
		assert.Error(t, yaml.Unmarshal([]byte(tt), &cfg), "Expected unmarshaling %q to become error, but not.", tt)
	}
}

func TestTimeEncodersParseFromJSON(t *testing.T) {
	moment := time.Unix(100, 50005000).UTC()
	tests := []struct {
		jsonDoc  string
		expected interface{} // output of serializing moment
	}{
		{`{"timeEncoder": "iso8601"}`, "1970-01-01T00:01:40.050Z"},
		{`{"timeEncoder": {"layout": "06/01/02 03:04pm"}}`, "70/01/01 12:01am"},
	}

	for _, tt := range tests {
		cfg := EncoderConfig{}
		require.NoError(t, json.Unmarshal([]byte(tt.jsonDoc), &cfg), "Unexpected error unmarshaling %q.", tt.jsonDoc)
		require.NotNil(t, cfg.EncodeTime, "Unmashalled timeEncoder is nil for %q.", tt.jsonDoc)
		assertAppended(
			t,
			tt.expected,
			func(arr ArrayEncoder) { cfg.EncodeTime(moment, arr) },
			"Unexpected output serializing %v with %q.", moment, tt.jsonDoc,
		)
	}
}

func TestDurationEncoders(t *testing.T) {
	elapsed := time.Second + 500*time.Nanosecond
	tests := []struct {
		name     string