Files
releases/plugins/logs/encoder_test.go
T
Torin Sandall 49bba1faa8 Add decision logging plugin
Previously, decision logs were kept in-memory and enabled via
diagnostics configuration. With these changes, admins can configure OPA
to log decisions to a remote HTTP endpoint.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-10 13:58:36 -07:00

52 lines
1.3 KiB
Go

// Copyright 2018 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package logs
import (
"bytes"
"testing"
)
func TestChunkEncoder(t *testing.T) {
enc := newChunkEncoder(1000)
bs, err := enc.Write(bytes.Repeat([]byte(`1`), 500))
if bs != nil || err != nil {
t.Fatalf("Unexpected error or chunk produced: err: %v", err)
}
bs, err = enc.Write(bytes.Repeat([]byte(`1`), 498))
if bs != nil || err != nil {
t.Fatalf("Unexpected error or chunk produced: err: %v", err)
}
bs, err = enc.Write(bytes.Repeat([]byte(`1`), 1))
if bs == nil || err != nil {
t.Fatalf("Unexpected error or NO chunk produced: err: %v", err)
}
bs, err = enc.Write(bytes.Repeat([]byte(`1`), 1))
if bs != nil || err != nil {
t.Fatalf("Unexpected error or chunk produced: err: %v", err)
}
bs, err = enc.Flush()
if bs == nil || err != nil {
t.Fatalf("Unexpected error or NO chunk produced: err: %v", err)
}
bs, err = enc.Flush()
if bs != nil || err != nil {
t.Fatalf("Unexpected error chunk produced: err: %v", err)
}
bs, err = enc.Write(nil)
if bs != nil || err != nil || enc.bytesWritten != 0 {
t.Fatalf("Unexpected error chunk produced or bytesWritten != 0: err: %v, bytesWritten: %v", err, enc.bytesWritten)
}
}