Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: do not panic if monitors undefined#442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 1 commit intomainfromfix-432
Sep 22, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletionsprovider/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -383,16 +383,28 @@ func agentResource() *schema.Resource {
}

if rd.HasChange("resources_monitoring") {
monitors, ok := rd.Get("resources_monitoring").(*schema.Set)
rmResource, ok := rd.Get("resources_monitoring").(*schema.Set)
if !ok {
return xerrors.Errorf("unexpected type %T for resources_monitoring.0.volume, expected []any", rd.Get("resources_monitoring.0.volume"))
return xerrors.Errorf("unexpected type %T for resources_monitoring, expected []any", rd.Get("resources_monitoring"))
}

monitor := monitors.List()[0].(map[string]any)
rmResourceAsList := rmResource.List()
if len(rmResourceAsList) == 0 {
return xerrors.Errorf("developer error: resources_monitoring cannot be empty")
}
rawMonitors := rmResourceAsList[0]
if rawMonitors == nil {
return xerrors.Errorf("resources_monitoring must define at least one monitor")
}

monitors, ok := rawMonitors.(map[string]any)
if !ok {
return xerrors.Errorf("unexpected type %T for resources_monitoring.0.volume, expected []any", rawMonitors)
}

volumes, ok :=monitor["volume"].(*schema.Set)
volumes, ok :=monitors["volume"].(*schema.Set)
if !ok {
return xerrors.Errorf("unexpected type %T for resources_monitoring.0.volume, expected []any",monitor["volume"])
return xerrors.Errorf("unexpected type %T for resources_monitoring.0.volume, expected []any",monitors["volume"])
}

paths := map[string]bool{}
Expand All@@ -403,7 +415,6 @@ func agentResource() *schema.Resource {
}

// print path for debug purpose

path, ok := obj["path"].(string)
if !ok {
return xerrors.Errorf("unexpected type %T for volume path, expected string", obj["path"])
Expand Down
20 changes: 20 additions & 0 deletionsprovider/agent_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -352,6 +352,26 @@ func TestAgent_ResourcesMonitoring(t *testing.T) {
})
})

t.Run("MissingMonitors", func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProviderFactories: coderFactory(),
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
url = "https://example.com"
}
resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
resources_monitoring {}
}`,
Check: nil,
ExpectError: regexp.MustCompile(`resources_monitoring must define at least one monitor`),
}},
})
})

t.Run("DuplicatePaths", func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProviderFactories: coderFactory(),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp