From 68dcac96453f4f6bc9e4b7c5ad194f61a28ac086 Mon Sep 17 00:00:00 2001 From: Guillaume Allee Date: Fri, 17 Nov 2023 14:29:26 +0100 Subject: [PATCH] add acceptance test for a template name not found + fix the #497 issue --- ovh/data_me_installation_template.go | 3 +++ ovh/data_me_installation_template_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/ovh/data_me_installation_template.go b/ovh/data_me_installation_template.go index b31c5f51b..d466a1ec4 100644 --- a/ovh/data_me_installation_template.go +++ b/ovh/data_me_installation_template.go @@ -254,6 +254,9 @@ func dataSourceMeInstallationTemplateRead(d *schema.ResourceData, meta interface if err != nil { return err } + if template == nil { + return fmt.Errorf("Your query returned no results. Please change your search criteria") + } // set attributes for k, v := range template.ToMap() { diff --git a/ovh/data_me_installation_template_test.go b/ovh/data_me_installation_template_test.go index b33d49f2c..040997936 100644 --- a/ovh/data_me_installation_template_test.go +++ b/ovh/data_me_installation_template_test.go @@ -2,6 +2,7 @@ package ovh import ( "fmt" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -45,10 +46,19 @@ func TestAccMeInstallationTemplateDataSource_basic(t *testing.T) { ), ), }, + { + Config: testAccMeInstallationTemplateDatasourceConfig_404, + ExpectError: regexp.MustCompile("Your query returned no results. Please change your search criteria"), + }, }, }) } +const testAccMeInstallationTemplateDatasourceConfig_404 = ` +data "ovh_me_installation_template" "template" { + template_name = "42" + } +` const testAccMeInstallationTemplateDatasourceConfig_Basic = ` resource "ovh_me_installation_template" "template" { base_template_name = "centos7_64"