-
-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathgrpc_test.go
More file actions
70 lines (57 loc) · 1.67 KB
/
Copy pathgrpc_test.go
File metadata and controls
70 lines (57 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cmd
import (
"os"
"path/filepath"
"runtime"
"testing"
"github.com/fullstorydev/grpchan/inprocgrpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.flipt.io/flipt/internal/config"
"go.flipt.io/flipt/internal/info"
flipt "go.flipt.io/flipt/rpc/flipt"
"go.uber.org/zap/zaptest"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func TestAuditLogsRecordedWhenTracingDisabled(t *testing.T) {
tmpDir := t.TempDir()
cfg := config.Default()
cfg.Database.URL = "file:" + filepath.ToSlash(filepath.Join(tmpDir, "flipt.db"))
cfg.Audit.Sinks.Log.Enabled = true
cfg.Audit.Sinks.Log.File = filepath.Join(tmpDir, "audit.log")
cfg.Server.GRPCPort = 0
logger := zaptest.NewLogger(t)
ctx := t.Context()
ipch := &inprocgrpc.Channel{}
server, err := NewGRPCServer(ctx, logger, cfg, ipch, info.Flipt{Version: t.Name()}, true)
require.NoError(t, err)
startServerChan := make(chan struct{})
go func() {
close(startServerChan)
err := server.Run()
assert.NoError(t, err)
}()
runtime.Gosched()
<-startServerChan
conn, err := grpc.NewClient(
server.ln.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
require.NoError(t, err)
t.Cleanup(func() {
_ = conn.Close()
})
client := flipt.NewFliptClient(conn)
_, err = client.CreateFlag(ctx, &flipt.CreateFlagRequest{
Key: "test-flag",
Name: "Test Flag",
Type: flipt.FlagType_VARIANT_FLAG_TYPE,
})
require.NoError(t, err)
_ = server.Shutdown(ctx)
data, err := os.ReadFile(cfg.Audit.Sinks.Log.File)
require.NoError(t, err)
assert.Contains(t, string(data), `"type": "flag"`)
assert.Contains(t, string(data), `"action": "created"`)
}