-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathvalidation_test.go
More file actions
90 lines (75 loc) · 2.63 KB
/
Copy pathvalidation_test.go
File metadata and controls
90 lines (75 loc) · 2.63 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package agentapi_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"storj.io/drpc/drpcerr"
agentproto "github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/coderd/agentapi"
"github.com/coder/coder/v2/codersdk/drpcsdk"
"github.com/coder/coder/v2/testutil"
)
func TestUpdateLifecycleMissingMessage(t *testing.T) {
t.Parallel()
resp, err := (&agentapi.LifecycleAPI{}).UpdateLifecycle(context.Background(), &agentproto.UpdateLifecycleRequest{})
require.ErrorContains(t, err, "lifecycle is required")
require.EqualValues(t, codes.InvalidArgument, drpcerr.Code(err))
require.Nil(t, resp)
}
func TestUpdateStartupMissingMessage(t *testing.T) {
t.Parallel()
resp, err := (&agentapi.LifecycleAPI{}).UpdateStartup(context.Background(), &agentproto.UpdateStartupRequest{})
require.ErrorContains(t, err, "startup is required")
require.EqualValues(t, codes.InvalidArgument, drpcerr.Code(err))
require.Nil(t, resp)
}
func TestBatchUpdateMetadataMissingMessage(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
req *agentproto.BatchUpdateMetadataRequest
}{
{name: "NilRequest"},
{name: "MixedBatch", req: &agentproto.BatchUpdateMetadataRequest{Metadata: []*agentproto.Metadata{
{Key: "valid", Result: &agentproto.WorkspaceAgentMetadata_Result{Value: "value"}},
{Key: "invalid"},
}}},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
resp, err := (&agentapi.MetadataAPI{}).BatchUpdateMetadata(context.Background(), tt.req)
require.Error(t, err)
require.EqualValues(t, codes.InvalidArgument, drpcerr.Code(err))
require.Nil(t, resp)
})
}
}
func TestAgentRPCMissingMessage(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
serverCtx, cancel := context.WithCancel(agentapi.WithAPIVersion(ctx, "2.0"))
defer cancel()
conn, listener := drpcsdk.MemTransportPipe()
defer conn.Close()
defer listener.Close()
api := &agentapi.API{
LifecycleAPI: &agentapi.LifecycleAPI{},
StatsAPI: &agentapi.StatsAPI{},
}
server, err := api.Server(serverCtx)
require.NoError(t, err)
done := make(chan error, 1)
go func() {
done <- server.Serve(serverCtx, listener)
}()
client := agentproto.NewDRPCAgentClient(conn)
_, err = client.UpdateLifecycle(ctx, &agentproto.UpdateLifecycleRequest{})
require.ErrorContains(t, err, "lifecycle is required")
require.EqualValues(t, codes.InvalidArgument, drpcerr.Code(err))
stats, err := client.UpdateStats(ctx, &agentproto.UpdateStatsRequest{})
require.NoError(t, err)
require.NotNil(t, stats.ReportInterval)
cancel()
require.NoError(t, testutil.RequireReceive(ctx, t, done))
}