1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

Adhere to new interfaces

This commit is contained in:
Jake Sanders 2019-12-17 17:24:01 +00:00
parent c2b307e5bb
commit 81e7edd666
3 changed files with 41 additions and 16 deletions

View File

@ -2,21 +2,23 @@
package kubernetes
import (
"errors"
"github.com/micro/go-micro/debug/log"
)
type klog struct{}
func (k *klog) Read(...log.ReadOption) []log.Record { return nil }
func (k *klog) Write(l log.Record) {
write(l)
func (k *klog) Read(...log.ReadOption) ([]log.Record, error) {
return nil, errors.New("not implemented")
}
func (k *klog) Stream() (<-chan log.Record, chan bool) {
c, s := make(chan log.Record), make(chan bool)
go close(c)
return c, s
func (k *klog) Write(l log.Record) error {
return write(l)
}
func (k *klog) Stream() (log.Stream, error) {
return &klogStreamer{}, nil
}
// New returns a configured Kubernetes logger

View File

@ -39,14 +39,18 @@ func TestKubernetes(t *testing.T) {
}
assert.Equal(t, write, read, "Write was not equal")
assert.Nil(t, k.Read(), "Read should be unimplemented")
_, err = k.Read()
assert.Error(t, err, "Read should be unimplemented")
stream, stop := k.Stream()
stream, err := k.Stream()
if err != nil {
t.Error(err)
}
records := []log.Record{}
for s := range stream {
go stream.Stop()
for s := range stream.Chan() {
records = append(records, s)
}
close(stop)
assert.Equal(t, 0, len(records), "Stream should be unimplemented")
assert.Equal(t, 0, len(records), "Stream should return nothing")
}

View File

@ -8,8 +8,27 @@ import (
"os"
)
func write(l log.Record) {
if m, err := json.Marshal(l); err == nil {
fmt.Fprintf(os.Stderr, "%s", m)
func write(l log.Record) error {
m, err := json.Marshal(l)
if err == nil {
_, err := fmt.Fprintf(os.Stderr, "%s", m)
return err
}
return err
}
type klogStreamer struct {
streamChan chan log.Record
}
func (k *klogStreamer) Chan() <-chan log.Record {
if k.streamChan == nil {
k.streamChan = make(chan log.Record)
}
return k.streamChan
}
func (k *klogStreamer) Stop() error {
close(k.streamChan)
return nil
}