-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,559 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"os" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func TestLicensingLicenseResouce(t *testing.T) { | ||
testLicense := os.Getenv("TF_ACC_NETAPP_LICENSE") | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccLicensingLicenseResourceConfig("testme"), | ||
ExpectError: regexp.MustCompile("1115159"), | ||
}, | ||
{ | ||
Config: testAccLicensingLicenseResourceConfig(testLicense), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_licensing_license_resource.cluster_licensing_license", "name", "insight_balance")), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccLicensingLicenseResourceConfig(key string) string { | ||
host := os.Getenv("TF_ACC_NETAPP_HOST") | ||
admin := os.Getenv("TF_ACC_NETAPP_USER") | ||
password := os.Getenv("TF_ACC_NETAPP_PASS") | ||
if host == "" || admin == "" || password == "" { | ||
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests") | ||
os.Exit(1) | ||
} | ||
return fmt.Sprintf(` | ||
provider "netapp-ontap" { | ||
connection_profiles = [ | ||
{ | ||
name = "cluster4" | ||
hostname = "%s" | ||
username = "%s" | ||
password = "%s" | ||
validate_certs = false | ||
}, | ||
] | ||
} | ||
resource "netapp-ontap_cluster_licensing_license_resource" "cluster_licensing_license" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
keys = ["%s"] | ||
} | ||
`, host, admin, password, key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccClusterScheduleResource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Test create interval schedule error | ||
{ | ||
Config: testAccClusterScheduleResourceIntervalConfig("non-existant", "wrongvalue"), | ||
ExpectError: regexp.MustCompile("error creating cluster_schedule"), | ||
}, | ||
// Create intervale and read | ||
{ | ||
Config: testAccClusterScheduleResourceIntervalConfig("tf-interval-schedule-test", "PT8M30S"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_schedule_resource.example", "name", "tf-interval-schedule-test"), | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_schedule_resource.example", "interval", "PT8M30S"), | ||
), | ||
}, | ||
// update and read | ||
{ | ||
Config: testAccClusterScheduleResourceIntervalConfig("tf-interval-schedule-test", "PT8M20S"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_schedule_resource.example", "name", "tf-interval-schedule-test"), | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_schedule_resource.example", "interval", "PT8M20S"), | ||
), | ||
}, | ||
// Create cron schedule and read | ||
{ | ||
Config: testAccClusterScheduleCreateResourceCronConfig("tf-cron-schedule-test"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_schedule_resource.cron-example", "name", "tf-cron-schedule-test"), | ||
), | ||
}, | ||
// Update cron schedule and read | ||
{ | ||
Config: testAccClusterScheduleUpdateResourceCronConfig("tf-cron-schedule-test"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_schedule_resource.cron-example", "name", "tf-cron-schedule-test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccClusterScheduleResourceIntervalConfig(name string, interval string) string { | ||
host := os.Getenv("TF_ACC_NETAPP_HOST") | ||
admin := os.Getenv("TF_ACC_NETAPP_USER") | ||
password := os.Getenv("TF_ACC_NETAPP_PASS") | ||
if host == "" || admin == "" || password == "" { | ||
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests") | ||
os.Exit(1) | ||
} | ||
return fmt.Sprintf(` | ||
provider "netapp-ontap" { | ||
connection_profiles = [ | ||
{ | ||
name = "cluster4" | ||
hostname = "%s" | ||
username = "%s" | ||
password = "%s" | ||
validate_certs = false | ||
}, | ||
] | ||
} | ||
resource "netapp-ontap_cluster_schedule_resource" "example" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
name = "%s" | ||
interval = "%s" | ||
}`, host, admin, password, name, interval) | ||
} | ||
|
||
func testAccClusterScheduleCreateResourceCronConfig(name string) string { | ||
host := os.Getenv("TF_ACC_NETAPP_HOST") | ||
admin := os.Getenv("TF_ACC_NETAPP_USER") | ||
password := os.Getenv("TF_ACC_NETAPP_PASS") | ||
if host == "" || admin == "" || password == "" { | ||
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests") | ||
os.Exit(1) | ||
} | ||
return fmt.Sprintf(` | ||
provider "netapp-ontap" { | ||
connection_profiles = [ | ||
{ | ||
name = "cluster4" | ||
hostname = "%s" | ||
username = "%s" | ||
password = "%s" | ||
validate_certs = false | ||
}, | ||
] | ||
} | ||
resource "netapp-ontap_cluster_schedule_resource" "cron-example" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
name = "%s" | ||
cron = { | ||
minutes = [1, 2, 3, 4] | ||
hours = [10] | ||
days = [1, 2] | ||
months = [6, 7] | ||
weekdays = [1, 3, 4] | ||
} | ||
}`, host, admin, password, name) | ||
} | ||
|
||
func testAccClusterScheduleUpdateResourceCronConfig(name string) string { | ||
host := os.Getenv("TF_ACC_NETAPP_HOST") | ||
admin := os.Getenv("TF_ACC_NETAPP_USER") | ||
password := os.Getenv("TF_ACC_NETAPP_PASS") | ||
if host == "" || admin == "" || password == "" { | ||
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests") | ||
os.Exit(1) | ||
} | ||
return fmt.Sprintf(` | ||
provider "netapp-ontap" { | ||
connection_profiles = [ | ||
{ | ||
name = "cluster4" | ||
hostname = "%s" | ||
username = "%s" | ||
password = "%s" | ||
validate_certs = false | ||
}, | ||
] | ||
} | ||
resource "netapp-ontap_cluster_schedule_resource" "cron-example" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
name = "%s" | ||
cron = { | ||
minutes = [4, 5, 6] | ||
hours = [2, 3] | ||
days = [2] | ||
months = [1, 6, 7] | ||
weekdays = [3, 4, 5] | ||
} | ||
}`, host, admin, password, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/netapp/terraform-provider-netapp-ontap/internal/restclient" | ||
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils" | ||
) | ||
|
||
func TestConfig_GetConnectionProfile(t *testing.T) { | ||
type fields struct { | ||
ConnectionProfiles map[string]ConnectionProfile | ||
Version string | ||
} | ||
type args struct { | ||
name string | ||
} | ||
cxProfile := ConnectionProfile{} | ||
cxProfiles := map[string]ConnectionProfile{"empty": cxProfile} | ||
cxProfilesTwo := map[string]ConnectionProfile{"empty1": cxProfile, "empty2": cxProfile} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *ConnectionProfile | ||
wantErr bool | ||
}{ | ||
{name: "test_found", fields: fields{ConnectionProfiles: cxProfiles, Version: "v1.2.3"}, args: args{name: "empty"}, want: &cxProfile, wantErr: false}, | ||
{name: "test_found_one_profile_no_name", fields: fields{ConnectionProfiles: cxProfiles, Version: "v1.2.3"}, args: args{name: ""}, want: &cxProfile, wantErr: false}, | ||
{name: "test_not_found", fields: fields{ConnectionProfiles: cxProfiles, Version: "v1.2.3"}, args: args{name: "other"}, want: nil, wantErr: true}, | ||
{name: "test_no_config", fields: fields{ConnectionProfiles: cxProfiles, Version: "v1.2.3"}, args: args{name: "other"}, want: nil, wantErr: true}, | ||
{name: "test_no_profiles", fields: fields{ConnectionProfiles: map[string]ConnectionProfile{}, Version: "v1.2.3"}, args: args{name: "other"}, want: nil, wantErr: true}, | ||
{name: "test_two_profiles_no_name", fields: fields{ConnectionProfiles: cxProfilesTwo, Version: "v1.2.3"}, args: args{name: ""}, want: nil, wantErr: true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
c := &Config{ | ||
ConnectionProfiles: tt.fields.ConnectionProfiles, | ||
Version: tt.fields.Version, | ||
} | ||
if tt.name == "test_no_config" { | ||
c = nil | ||
} | ||
|
||
got, err := c.GetConnectionProfile(tt.args.name) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Config.GetConnectionProfile() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("Config.GetConnectionProfile() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestConfig_NewClient(t *testing.T) { | ||
type fields struct { | ||
ConnectionProfiles map[string]ConnectionProfile | ||
Version string | ||
} | ||
cxProfile := ConnectionProfile{} | ||
cxProfiles := map[string]ConnectionProfile{"empty": cxProfile} | ||
// cxProfilesTwo := map[string]ConnectionProfile{"empty1": cxProfile, "empty2": cxProfile} | ||
restClient, err := restclient.NewClient(context.Background(), restclient.ConnectionProfile{}, "TerrafromONTAP/config_test/v1.2.3", 600) | ||
if err != nil { | ||
panic(err) | ||
} | ||
errorHandler := utils.NewErrorHandler(context.Background(), &diag.Diagnostics{}) | ||
|
||
tests := []struct { | ||
name string | ||
fields fields | ||
cxProfileName string | ||
resName string | ||
want *restclient.RestClient | ||
wantErr bool | ||
}{ | ||
{name: "test_found", fields: fields{ConnectionProfiles: cxProfiles, Version: "v1.2.3"}, cxProfileName: "empty", resName: "config_test", want: restClient, wantErr: false}, | ||
{name: "test_not_found", fields: fields{ConnectionProfiles: cxProfiles, Version: "v1.2.3"}, cxProfileName: "other", want: nil, wantErr: true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
c := &Config{ | ||
ConnectionProfiles: tt.fields.ConnectionProfiles, | ||
Version: tt.fields.Version, | ||
} | ||
got, err := c.NewClient(errorHandler, tt.cxProfileName, tt.resName) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Config.NewClient() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got == nil || tt.want == nil { | ||
if got != tt.want { | ||
t.Errorf("Config.NewClient() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
} else if ok, diffs := tt.want.Equals(got); !ok { | ||
t.Errorf(diffs) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package provider | ||
|
||
//func TestAccExampleDataSource(t *testing.T) { | ||
// resource.Test(t, resource.TestCase{ | ||
// PreCheck: func() { testAccPreCheck(t) }, | ||
// ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
// Steps: []resource.TestStep{ | ||
// // Read testing | ||
// { | ||
// Config: testAccExampleDataSourceConfig, | ||
// Check: resource.ComposeAggregateTestCheckFunc( | ||
// resource.TestCheckResourceAttr("data.netapp-ontap_example.test", "id", "example-id"), | ||
// ), | ||
// }, | ||
// }, | ||
// }) | ||
//} | ||
|
||
const testAccExampleDataSourceConfig = ` | ||
data "netapp-ontap_example" "test" { | ||
configurable_attribute = "example" | ||
} | ||
` |
Oops, something went wrong.