Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec429fb

Browse files
committed
improve formatting
1 parent 1423f26 commit ec429fb

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

agent/agent_test.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,43 @@ func TestAgent_StartupScript(t *testing.T) {
869869
func TestAgent_Metadata(t *testing.T) {
870870
t.Parallel()
871871

872-
t.Run("Basic", func(t *testing.T) {
872+
t.Run("Once", func(t *testing.T) {
873+
t.Parallel()
874+
script := "echo -n hello"
875+
if runtime.GOOS == "windows" {
876+
script = "powershell " + script
877+
}
878+
//nolint:dogsled
879+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
880+
Metadata: []codersdk.WorkspaceAgentMetadataDescription{
881+
{
882+
Key: "greeting",
883+
Interval: 0,
884+
Script: script,
885+
},
886+
},
887+
}, 0)
888+
889+
var gotMd map[string]agentsdk.PostMetadataRequest
890+
require.Eventually(t, func() bool {
891+
gotMd = client.getMetadata()
892+
return len(gotMd) == 1
893+
}, testutil.WaitShort, testutil.IntervalMedium)
894+
895+
collectedAt := gotMd["greeting"].CollectedAt
896+
897+
require.Never(t, func() bool {
898+
gotMd = client.getMetadata()
899+
if len(gotMd) != 1 {
900+
panic("unexpected number of metadata")
901+
}
902+
return !gotMd["greeting"].CollectedAt.Equal(collectedAt)
903+
}, testutil.WaitShort, testutil.IntervalMedium)
904+
})
905+
906+
t.Run("Many", func(t *testing.T) {
873907
if runtime.GOOS == "windows" {
874-
// Shell scripting in Windows is a pain, so but we test that it works in the simpler "CollectOnce"
908+
// Shell scripting in Windows is a pain, but we test that it works in the simpler "CollectOnce"
875909
// test.
876910
t.Skip()
877911
}
@@ -906,8 +940,7 @@ func TestAgent_Metadata(t *testing.T) {
906940
panic("unexpected number of metadata entries")
907941
}
908942

909-
// Trim space to be OS-newline agnostic.
910-
require.Equal(t, "hello", strings.TrimSpace(md["greeting"].Value))
943+
require.Equal(t, "hello\n", md["greeting"].Value)
911944
require.Equal(t, "exit status 1", md["bad"].Error)
912945

913946
greetingByt, err := os.ReadFile(greetingPath)
@@ -920,7 +953,7 @@ func TestAgent_Metadata(t *testing.T) {
920953
lowerBound = (int(idealNumGreetings) / 2)
921954
)
922955

923-
if idealNumGreetings < 5 {
956+
if idealNumGreetings < 10 {
924957
// Not enough time has passed to get a good sample size.
925958
continue
926959
}
@@ -936,39 +969,6 @@ func TestAgent_Metadata(t *testing.T) {
936969
}
937970
})
938971

939-
t.Run("CollectOnce", func(t *testing.T) {
940-
t.Parallel()
941-
script := "echo -n hello"
942-
if runtime.GOOS == "windows" {
943-
script = "powershell " + script
944-
}
945-
//nolint:dogsled
946-
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
947-
Metadata: []codersdk.WorkspaceAgentMetadataDescription{
948-
{
949-
Key: "greeting",
950-
Interval: 0,
951-
Script: script,
952-
},
953-
},
954-
}, 0)
955-
956-
var gotMd map[string]agentsdk.PostMetadataRequest
957-
require.Eventually(t, func() bool {
958-
gotMd = client.getMetadata()
959-
return len(gotMd) == 1
960-
}, testutil.WaitShort, testutil.IntervalMedium)
961-
962-
collectedAt := gotMd["greeting"].CollectedAt
963-
964-
require.Never(t, func() bool {
965-
gotMd = client.getMetadata()
966-
if len(gotMd) != 1 {
967-
panic("unexpected number of metadata")
968-
}
969-
return !gotMd["greeting"].CollectedAt.Equal(collectedAt)
970-
}, testutil.WaitShort, testutil.IntervalMedium)
971-
})
972972
}
973973

974974
func TestAgent_Lifecycle(t *testing.T) {

0 commit comments

Comments
 (0)