From 4d59f2d613e7cbcef21eab69b100a4c968099319 Mon Sep 17 00:00:00 2001 From: Heather Lanigan Date: Mon, 26 Aug 2024 17:58:33 -0400 Subject: [PATCH] fix: bugs 535 and 539 only find storage for application being read Call full status with a filter of the application name when Reading, this ensures that the returned storage is for the current application only. Updated an application acceptance test to ensure storage isn't written for applications without storage. --- internal/juju/applications.go | 10 +++++----- internal/provider/resource_application_test.go | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/juju/applications.go b/internal/juju/applications.go index b01e01f2..981b1506 100644 --- a/internal/juju/applications.go +++ b/internal/juju/applications.go @@ -901,12 +901,12 @@ func (c applicationsClient) ReadApplication(input *ReadApplicationInput) (*ReadA appInfo := apps[0].Result - // We are currently retrieving the full status, which might be more information than necessary. - // The main focus is on the application status, particularly including the storage status. - // It might be more efficient to directly query for the application status and its associated storage status. - // TODO: Investigate if there's a way to optimize this by only fetching the required information. + // Fetch data only about the application being read. This helps to limit + // the data on storage to the specific application too. Storage is not + // provided by application, rather storage data buries a unit name deep + // in the structure. status, err := clientAPIClient.Status(&apiclient.StatusArgs{ - Patterns: []string{}, + Patterns: []string{input.AppName}, IncludeStorage: true, }) if err != nil { diff --git a/internal/provider/resource_application_test.go b/internal/provider/resource_application_test.go index 93066573..a1e66528 100644 --- a/internal/provider/resource_application_test.go +++ b/internal/provider/resource_application_test.go @@ -41,6 +41,7 @@ func TestAcc_ResourceApplication(t *testing.T) { resource.TestCheckResourceAttr("juju_application.this", "charm.0.name", "jameinel-ubuntu-lite"), resource.TestCheckResourceAttr("juju_application.this", "trust", "true"), resource.TestCheckResourceAttr("juju_application.this", "expose.#", "1"), + resource.TestCheckNoResourceAttr("juju_application.this", "storage"), ), }, {