mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 10:26:29 +02:00
* core/ci: update linting * re-add exportloopref * re-add gocheckcompilerdirectives * re-add stylecheck * re-add usestdlibvars * upgrade lint --------- Co-authored-by: Denis Mishin <dmishin@pomerium.com>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package reconciler
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/encoding/protodelim"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"github.com/pomerium/pomerium/pkg/grpc/config"
|
|
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
|
"github.com/pomerium/pomerium/pkg/protoutil"
|
|
)
|
|
|
|
func TestReadRecords(t *testing.T) {
|
|
dir := t.TempDir()
|
|
fd, err := os.CreateTemp(dir, "config")
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() { _ = fd.Close() })
|
|
|
|
err = writeSampleRecords(fd)
|
|
require.NoError(t, err)
|
|
|
|
_, err = fd.Seek(0, io.SeekStart)
|
|
require.NoError(t, err)
|
|
|
|
records, err := ReadBundleRecords(fd)
|
|
require.NoError(t, err)
|
|
require.Len(t, records, 1)
|
|
}
|
|
|
|
func writeSampleRecords(dst io.Writer) error {
|
|
marshalOpts := protodelim.MarshalOptions{
|
|
MarshalOptions: proto.MarshalOptions{
|
|
AllowPartial: false,
|
|
Deterministic: true,
|
|
UseCachedSize: false,
|
|
},
|
|
}
|
|
|
|
cfg := protoutil.NewAny(&config.Config{
|
|
Routes: []*config.Route{
|
|
{
|
|
From: "https://from.example.com",
|
|
To: []string{"https://to.example.com"},
|
|
},
|
|
},
|
|
})
|
|
rec := &databroker.Record{
|
|
Id: "config",
|
|
Type: cfg.GetTypeUrl(),
|
|
Data: cfg,
|
|
}
|
|
_, err := marshalOpts.MarshalTo(dst, rec)
|
|
if err != nil {
|
|
return fmt.Errorf("marshal: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|