Skip to content

Commit c069563

Browse files
authored
test: fix use of t.Logf where t.Log would suffice (#16328)
1 parent 6caa29a commit c069563

File tree

15 files changed

+39
-39
lines changed

15 files changed

+39
-39
lines changed

agent/agent_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ func TestAgent_UpdatedDERP(t *testing.T) {
19621962
// Push a new DERP map to the agent.
19631963
err := client.PushDERPMapUpdate(newDerpMap)
19641964
require.NoError(t, err)
1965-
t.Logf("pushed DERPMap update to agent")
1965+
t.Log("pushed DERPMap update to agent")
19661966

19671967
require.Eventually(t, func() bool {
19681968
conn := uut.TailnetConn()
@@ -1974,7 +1974,7 @@ func TestAgent_UpdatedDERP(t *testing.T) {
19741974
t.Logf("agent Conn DERPMap with regionIDs %v, PreferredDERP %d", regionIDs, preferredDERP)
19751975
return len(regionIDs) == 1 && regionIDs[0] == 2 && preferredDERP == 2
19761976
}, testutil.WaitLong, testutil.IntervalFast)
1977-
t.Logf("agent got the new DERPMap")
1977+
t.Log("agent got the new DERPMap")
19781978

19791979
// Connect from a second client and make sure it uses the new DERP map.
19801980
conn2 := newClientConn(newDerpMap, "client2")

cli/clilog/clilog_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func assertLogs(t testing.TB, path string, expected ...string) {
181181

182182
logs := strings.Split(strings.TrimSpace(string(data)), "\n")
183183
if !assert.Len(t, logs, len(expected)) {
184-
t.Logf(string(data))
184+
t.Log(string(data))
185185
t.FailNow()
186186
}
187187
for i, log := range logs {
@@ -202,7 +202,7 @@ func assertLogsJSON(t testing.TB, path string, levelExpected ...string) {
202202

203203
logs := strings.Split(strings.TrimSpace(string(data)), "\n")
204204
if !assert.Len(t, logs, len(levelExpected)/2) {
205-
t.Logf(string(data))
205+
t.Log(string(data))
206206
t.FailNow()
207207
}
208208
for i, log := range logs {

coderd/database/dbpurge/dbpurge_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestDeleteOldWorkspaceAgentStats(t *testing.T) {
6666

6767
defer func() {
6868
if t.Failed() {
69-
t.Logf("Test failed, printing rows...")
69+
t.Log("Test failed, printing rows...")
7070
ctx := testutil.Context(t, testutil.WaitShort)
7171
buf := &bytes.Buffer{}
7272
enc := json.NewEncoder(buf)

coderd/database/migrations/migrate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ func TestMigrateUpWithFixtures(t *testing.T) {
283283
}
284284
}
285285
if len(emptyTables) > 0 {
286-
t.Logf("The following tables have zero rows, consider adding fixtures for them or create a full database dump:")
286+
t.Log("The following tables have zero rows, consider adding fixtures for them or create a full database dump:")
287287
t.Errorf("tables have zero rows: %v", emptyTables)
288-
t.Logf("See https://github.com/coder/coder/blob/main/docs/CONTRIBUTING.md#database-fixtures-for-testing-migrations for more information")
288+
t.Log("See https://github.com/coder/coder/blob/main/docs/CONTRIBUTING.md#database-fixtures-for-testing-migrations for more information")
289289
}
290290
})
291291

coderd/notifications/notifications_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func TestBackpressure(t *testing.T) {
388388
}, testutil.WaitShort, testutil.IntervalFast)
389389
}
390390
}
391-
t.Logf("done advancing")
391+
t.Log("done advancing")
392392
// The batch completes
393393
w.MustWait(ctx)
394394

coderd/provisionerdserver/acquirer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ func TestAcquirer_MatchTags(t *testing.T) {
547547
s := fmt.Sprintf("| %s | %s | %s | %s |", kvs(tt.acquireJobTags), kvs(tt.provisionerJobTags), sameOrg, acquire)
548548
lines = append(lines, s)
549549
}
550-
t.Logf("You can paste this into docs/admin/provisioners.md")
551-
t.Logf(strings.Join(lines, "\n"))
550+
t.Log("You can paste this into docs/admin/provisioners.md")
551+
t.Log(strings.Join(lines, "\n"))
552552
})
553553
}
554554

coderd/provisionerdserver/provisionerdserver_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestHeartbeat(t *testing.T) {
101101
ctx := testutil.Context(t, testutil.WaitShort)
102102
heartbeatChan := make(chan struct{})
103103
heartbeatFn := func(hbCtx context.Context) error {
104-
t.Logf("heartbeat")
104+
t.Log("heartbeat")
105105
select {
106106
case <-hbCtx.Done():
107107
return hbCtx.Err()

coderd/workspacestats/batcher_internal_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestBatchStats(t *testing.T) {
5353
tick <- t1
5454
f := <-flushed
5555
require.Equal(t, 0, f, "expected no data to be flushed")
56-
t.Logf("flush 1 completed")
56+
t.Log("flush 1 completed")
5757

5858
// Then: it should report no stats.
5959
stats, err := store.GetWorkspaceAgentStats(ctx, t1)
@@ -62,15 +62,15 @@ func TestBatchStats(t *testing.T) {
6262

6363
// Given: a single data point is added for workspace
6464
t2 := t1.Add(time.Second)
65-
t.Logf("inserting 1 stat")
65+
t.Log("inserting 1 stat")
6666
b.Add(t2.Add(time.Millisecond), deps1.Agent.ID, deps1.User.ID, deps1.Template.ID, deps1.Workspace.ID, randStats(t), false)
6767

6868
// When: it becomes time to report stats
6969
// Signal a tick and wait for a flush to complete.
7070
tick <- t2
7171
f = <-flushed // Wait for a flush to complete.
7272
require.Equal(t, 1, f, "expected one stat to be flushed")
73-
t.Logf("flush 2 completed")
73+
t.Log("flush 2 completed")
7474

7575
// Then: it should report a single stat.
7676
stats, err = store.GetWorkspaceAgentStats(ctx, t2)
@@ -97,7 +97,7 @@ func TestBatchStats(t *testing.T) {
9797
// When: the buffer comes close to capacity
9898
// Then: The buffer will force-flush once.
9999
f = <-flushed
100-
t.Logf("flush 3 completed")
100+
t.Log("flush 3 completed")
101101
require.Greater(t, f, 819, "expected at least 819 stats to be flushed (>=80% of buffer)")
102102
// And we should finish inserting the stats
103103
<-done
@@ -110,7 +110,7 @@ func TestBatchStats(t *testing.T) {
110110
t4 := t3.Add(time.Second)
111111
tick <- t4
112112
f2 := <-flushed
113-
t.Logf("flush 4 completed")
113+
t.Log("flush 4 completed")
114114
expectedCount := defaultBufferSize - f
115115
require.Equal(t, expectedCount, f2, "did not flush expected remaining rows")
116116

@@ -119,7 +119,7 @@ func TestBatchStats(t *testing.T) {
119119
tick <- t5
120120
f = <-flushed
121121
require.Zero(t, f, "expected zero stats to have been flushed")
122-
t.Logf("flush 5 completed")
122+
t.Log("flush 5 completed")
123123

124124
stats, err = store.GetWorkspaceAgentStats(ctx, t5)
125125
require.NoError(t, err, "should not error getting stats")

codersdk/deployment_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ func TestDeploymentValues_DurationFormatNanoseconds(t *testing.T) {
309309
continue
310310
}
311311
t.Logf("Option %q is a duration but does not have the format_duration annotation.", s.Name)
312-
t.Logf("To fix this, add the following to the option declaration:")
313-
t.Logf(`Annotations: serpent.Annotations{}.Mark(annotationFormatDurationNS, "true"),`)
312+
t.Log("To fix this, add the following to the option declaration:")
313+
t.Log(`Annotations: serpent.Annotations{}.Mark(annotationFormatDurationNS, "true"),`)
314314
t.FailNow()
315315
}
316316
}

enterprise/cli/server_dbcrypt_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestServerDBCrypt(t *testing.T) {
4444
db := database.New(sqlDB)
4545

4646
// Populate the database with some unencrypted data.
47-
t.Logf("Generating unencrypted data")
47+
t.Log("Generating unencrypted data")
4848
users := genData(t, db)
4949

5050
// Setup an initial cipher A
@@ -57,7 +57,7 @@ func TestServerDBCrypt(t *testing.T) {
5757
require.NoError(t, err)
5858

5959
// Populate the database with some encrypted data using cipher A.
60-
t.Logf("Generating data encrypted with cipher A")
60+
t.Log("Generating data encrypted with cipher A")
6161
newUsers := genData(t, cryptdb)
6262

6363
// Validate that newly created users were encrypted with cipher A
@@ -67,7 +67,7 @@ func TestServerDBCrypt(t *testing.T) {
6767
users = append(users, newUsers...)
6868

6969
// Encrypt all the data with the initial cipher.
70-
t.Logf("Encrypting all data with cipher A")
70+
t.Log("Encrypting all data with cipher A")
7171
inv, _ := newCLI(t, "server", "dbcrypt", "rotate",
7272
"--postgres-url", connectionURL,
7373
"--new-key", base64.StdEncoding.EncodeToString([]byte(keyA)),
@@ -89,7 +89,7 @@ func TestServerDBCrypt(t *testing.T) {
8989
cipherBA, err := dbcrypt.NewCiphers([]byte(keyB), []byte(keyA))
9090
require.NoError(t, err)
9191

92-
t.Logf("Enrypting all data with cipher B")
92+
t.Log("Enrypting all data with cipher B")
9393
inv, _ = newCLI(t, "server", "dbcrypt", "rotate",
9494
"--postgres-url", connectionURL,
9595
"--new-key", base64.StdEncoding.EncodeToString([]byte(keyB)),
@@ -108,7 +108,7 @@ func TestServerDBCrypt(t *testing.T) {
108108
}
109109

110110
// Assert that we can revoke the old key.
111-
t.Logf("Revoking cipher A")
111+
t.Log("Revoking cipher A")
112112
err = db.RevokeDBCryptKey(ctx, cipherA[0].HexDigest())
113113
require.NoError(t, err, "failed to revoke old key")
114114

@@ -124,15 +124,15 @@ func TestServerDBCrypt(t *testing.T) {
124124
require.Empty(t, oldKey.ActiveKeyDigest.String, "expected the old key to not be active")
125125

126126
// Revoking the new key should fail.
127-
t.Logf("Attempting to revoke cipher B should fail as it is still in use")
127+
t.Log("Attempting to revoke cipher B should fail as it is still in use")
128128
err = db.RevokeDBCryptKey(ctx, cipherBA[0].HexDigest())
129129
require.Error(t, err, "expected to fail to revoke the new key")
130130
var pgErr *pq.Error
131131
require.True(t, xerrors.As(err, &pgErr), "expected a pg error")
132132
require.EqualValues(t, "23503", pgErr.Code, "expected a foreign key constraint violation error")
133133

134134
// Decrypt the data using only cipher B. This should result in the key being revoked.
135-
t.Logf("Decrypting with cipher B")
135+
t.Log("Decrypting with cipher B")
136136
inv, _ = newCLI(t, "server", "dbcrypt", "decrypt",
137137
"--postgres-url", connectionURL,
138138
"--keys", base64.StdEncoding.EncodeToString([]byte(keyB)),
@@ -162,7 +162,7 @@ func TestServerDBCrypt(t *testing.T) {
162162
cipherC, err := dbcrypt.NewCiphers([]byte(keyC))
163163
require.NoError(t, err)
164164

165-
t.Logf("Re-encrypting with cipher C")
165+
t.Log("Re-encrypting with cipher C")
166166
inv, _ = newCLI(t, "server", "dbcrypt", "rotate",
167167
"--postgres-url", connectionURL,
168168
"--new-key", base64.StdEncoding.EncodeToString([]byte(keyC)),
@@ -181,7 +181,7 @@ func TestServerDBCrypt(t *testing.T) {
181181
}
182182

183183
// Now delete all the encrypted data.
184-
t.Logf("Deleting all encrypted data")
184+
t.Log("Deleting all encrypted data")
185185
inv, _ = newCLI(t, "server", "dbcrypt", "delete",
186186
"--postgres-url", connectionURL,
187187
"--external-token-encryption-keys", base64.StdEncoding.EncodeToString([]byte(keyC)),

enterprise/coderd/templates_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ func TestMultipleOrganizationTemplates(t *testing.T) {
20182018
t.Logf("Second organization: %s", second.ID.String())
20192019
t.Logf("Third organization: %s", third.ID.String())
20202020

2021-
t.Logf("Creating template version in second organization")
2021+
t.Log("Creating template version in second organization")
20222022

20232023
start := time.Now()
20242024
version := coderdtest.CreateTemplateVersion(t, templateAdmin, second.ID, nil)

enterprise/tailnet/pgcoord_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -462,33 +462,33 @@ func TestPGCoordinatorDual_Mainline(t *testing.T) {
462462
defer client22.Close(ctx)
463463
t.Logf("client22=%s", client22.ID)
464464

465-
t.Logf("client11 -> Node 11")
465+
t.Log("client11 -> Node 11")
466466
client11.UpdateDERP(11)
467467
agent1.AssertEventuallyHasDERP(client11.ID, 11)
468468

469-
t.Logf("client21 -> Node 21")
469+
t.Log("client21 -> Node 21")
470470
client21.UpdateDERP(21)
471471
agent1.AssertEventuallyHasDERP(client21.ID, 21)
472472

473-
t.Logf("client22 -> Node 22")
473+
t.Log("client22 -> Node 22")
474474
client22.UpdateDERP(22)
475475
agent2.AssertEventuallyHasDERP(client22.ID, 22)
476476

477-
t.Logf("agent2 -> Node 2")
477+
t.Log("agent2 -> Node 2")
478478
agent2.UpdateDERP(2)
479479
client22.AssertEventuallyHasDERP(agent2.ID, 2)
480480
client12.AssertEventuallyHasDERP(agent2.ID, 2)
481481

482-
t.Logf("client12 -> Node 12")
482+
t.Log("client12 -> Node 12")
483483
client12.UpdateDERP(12)
484484
agent2.AssertEventuallyHasDERP(client12.ID, 12)
485485

486-
t.Logf("agent1 -> Node 1")
486+
t.Log("agent1 -> Node 1")
487487
agent1.UpdateDERP(1)
488488
client21.AssertEventuallyHasDERP(agent1.ID, 1)
489489
client11.AssertEventuallyHasDERP(agent1.ID, 1)
490490

491-
t.Logf("close coord2")
491+
t.Log("close coord2")
492492
err = coord2.Close()
493493
require.NoError(t, err)
494494

provisioner/terraform/internal/timings_test_utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TimingsAreEqual(t *testing.T, expected []*proto.Timing, actual []*proto.Tim
4040

4141
// Shortcut check.
4242
if len(expected)+len(actual) == 0 {
43-
t.Logf("both timings are empty")
43+
t.Log("both timings are empty")
4444
return true
4545
}
4646

provisioner/terraform/timings_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestTimingsFromProvision(t *testing.T) {
2828
// Given: a fake terraform bin that behaves as we expect it to.
2929
fakeBin := filepath.Join(cwd, "testdata", "timings-aggregation/fake-terraform.sh")
3030

31-
t.Logf(fakeBin)
31+
t.Log(fakeBin)
3232

3333
ctx, api := setupProvisioner(t, &provisionerServeOptions{
3434
binaryPath: fakeBin,

tailnet/test/integration/integration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ func ExecBackground(t *testing.T, processName string, netNS *os.File, name strin
592592
select {
593593
case err := <-waitErr:
594594
if err != nil {
595-
t.Logf("subprocess exited: " + err.Error())
595+
t.Log("subprocess exited: " + err.Error())
596596
}
597597
return
598598
default:

0 commit comments

Comments
 (0)