@@ -10,9 +10,7 @@ import (
10
10
agentproto "github.com/coder/coder/v2/agent/proto"
11
11
"github.com/coder/coder/v2/coderd/coderdtest"
12
12
"github.com/coder/coder/v2/coderd/database"
13
- "github.com/coder/coder/v2/coderd/database/dbauthz"
14
13
"github.com/coder/coder/v2/coderd/database/dbfake"
15
- "github.com/coder/coder/v2/coderd/rbac"
16
14
"github.com/coder/coder/v2/codersdk/agentsdk"
17
15
"github.com/coder/coder/v2/provisionersdk/proto"
18
16
"github.com/coder/coder/v2/testutil"
@@ -22,118 +20,46 @@ import (
22
20
func TestWorkspaceAgentReportStats (t * testing.T ) {
23
21
t .Parallel ()
24
22
25
- t .Run ("OK" , func (t * testing.T ) {
26
- t .Parallel ()
23
+ client , db := coderdtest .NewWithDatabase (t , nil )
24
+ user := coderdtest .CreateFirstUser (t , client )
25
+ r := dbfake .WorkspaceBuild (t , db , database.Workspace {
26
+ OrganizationID : user .OrganizationID ,
27
+ OwnerID : user .UserID ,
28
+ }).WithAgent ().Do ()
27
29
28
- client , db := coderdtest .NewWithDatabase (t , nil )
29
- user := coderdtest .CreateFirstUser (t , client )
30
- r := dbfake .WorkspaceBuild (t , db , database.Workspace {
31
- OrganizationID : user .OrganizationID ,
32
- OwnerID : user .UserID ,
33
- }).WithAgent ().Do ()
34
-
35
- ac := agentsdk .New (client .URL )
36
- ac .SetSessionToken (r .AgentToken )
37
- conn , err := ac .ConnectRPC (context .Background ())
38
- require .NoError (t , err )
39
- defer func () {
40
- _ = conn .Close ()
41
- }()
42
- agentAPI := agentproto .NewDRPCAgentClient (conn )
43
-
44
- _ , err = agentAPI .UpdateStats (context .Background (), & agentproto.UpdateStatsRequest {
45
- Stats : & agentproto.Stats {
46
- ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
47
- ConnectionCount : 1 ,
48
- RxPackets : 1 ,
49
- RxBytes : 1 ,
50
- TxPackets : 1 ,
51
- TxBytes : 1 ,
52
- SessionCountVscode : 1 ,
53
- SessionCountJetbrains : 0 ,
54
- SessionCountReconnectingPty : 0 ,
55
- SessionCountSsh : 0 ,
56
- ConnectionMedianLatencyMs : 10 ,
57
- },
58
- })
59
- require .NoError (t , err )
60
-
61
- newWorkspace , err := client .Workspace (context .Background (), r .Workspace .ID )
62
- require .NoError (t , err )
30
+ ac := agentsdk .New (client .URL )
31
+ ac .SetSessionToken (r .AgentToken )
32
+ conn , err := ac .ConnectRPC (context .Background ())
33
+ require .NoError (t , err )
34
+ defer func () {
35
+ _ = conn .Close ()
36
+ }()
37
+ agentAPI := agentproto .NewDRPCAgentClient (conn )
63
38
64
- assert .True (t ,
65
- newWorkspace .LastUsedAt .After (r .Workspace .LastUsedAt ),
66
- "%s is not after %s" , newWorkspace .LastUsedAt , r .Workspace .LastUsedAt ,
67
- )
39
+ _ , err = agentAPI .UpdateStats (context .Background (), & agentproto.UpdateStatsRequest {
40
+ Stats : & agentproto.Stats {
41
+ ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
42
+ ConnectionCount : 1 ,
43
+ RxPackets : 1 ,
44
+ RxBytes : 1 ,
45
+ TxPackets : 1 ,
46
+ TxBytes : 1 ,
47
+ SessionCountVscode : 1 ,
48
+ SessionCountJetbrains : 0 ,
49
+ SessionCountReconnectingPty : 0 ,
50
+ SessionCountSsh : 0 ,
51
+ ConnectionMedianLatencyMs : 10 ,
52
+ },
68
53
})
54
+ require .NoError (t , err )
69
55
70
- t .Run ("FailDeleted" , func (t * testing.T ) {
71
- t .Parallel ()
72
-
73
- owner , db := coderdtest .NewWithDatabase (t , nil )
74
- ownerUser := coderdtest .CreateFirstUser (t , owner )
75
- client , admin := coderdtest .CreateAnotherUser (t , owner , ownerUser .OrganizationID , rbac .RoleTemplateAdmin (), rbac .RoleUserAdmin ())
76
- r := dbfake .WorkspaceBuild (t , db , database.Workspace {
77
- OrganizationID : admin .OrganizationIDs [0 ],
78
- OwnerID : admin .ID ,
79
- }).WithAgent ().Do ()
80
-
81
- ac := agentsdk .New (client .URL )
82
- ac .SetSessionToken (r .AgentToken )
83
- conn , err := ac .ConnectRPC (context .Background ())
84
- require .NoError (t , err )
85
- defer func () {
86
- _ = conn .Close ()
87
- }()
88
- agentAPI := agentproto .NewDRPCAgentClient (conn )
89
-
90
- _ , err = agentAPI .UpdateStats (context .Background (), & agentproto.UpdateStatsRequest {
91
- Stats : & agentproto.Stats {
92
- ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
93
- ConnectionCount : 1 ,
94
- RxPackets : 1 ,
95
- RxBytes : 1 ,
96
- TxPackets : 1 ,
97
- TxBytes : 1 ,
98
- SessionCountVscode : 0 ,
99
- SessionCountJetbrains : 0 ,
100
- SessionCountReconnectingPty : 0 ,
101
- SessionCountSsh : 0 ,
102
- ConnectionMedianLatencyMs : 10 ,
103
- },
104
- })
105
- require .NoError (t , err )
106
-
107
- newWorkspace , err := client .Workspace (context .Background (), r .Workspace .ID )
108
- require .NoError (t , err )
109
-
110
- // nolint:gocritic // using db directly over creating a delete job
111
- err = db .UpdateWorkspaceDeletedByID (dbauthz .As (context .Background (),
112
- coderdtest .AuthzUserSubject (admin , ownerUser .OrganizationID )),
113
- database.UpdateWorkspaceDeletedByIDParams {
114
- ID : newWorkspace .ID ,
115
- Deleted : true ,
116
- })
117
- require .NoError (t , err )
56
+ newWorkspace , err := client .Workspace (context .Background (), r .Workspace .ID )
57
+ require .NoError (t , err )
118
58
119
- resp , err := agentAPI .UpdateStats (context .Background (), & agentproto.UpdateStatsRequest {
120
- Stats : & agentproto.Stats {
121
- ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
122
- ConnectionCount : 1 ,
123
- RxPackets : 1 ,
124
- RxBytes : 1 ,
125
- TxPackets : 1 ,
126
- TxBytes : 1 ,
127
- SessionCountVscode : 1 ,
128
- SessionCountJetbrains : 0 ,
129
- SessionCountReconnectingPty : 0 ,
130
- SessionCountSsh : 0 ,
131
- ConnectionMedianLatencyMs : 10 ,
132
- },
133
- })
134
- require .Nil (t , resp )
135
- require .ErrorContains (t , err , "agent is invalid" )
136
- })
59
+ assert .True (t ,
60
+ newWorkspace .LastUsedAt .After (r .Workspace .LastUsedAt ),
61
+ "%s is not after %s" , newWorkspace .LastUsedAt , r .Workspace .LastUsedAt ,
62
+ )
137
63
}
138
64
139
65
func TestAgentAPI_LargeManifest (t * testing.T ) {
0 commit comments