@@ -450,65 +450,109 @@ var testAccProviderFactoriesInternal = map[string]func() (*schema.Provider, erro
450450 },
451451}
452452
453- func TestAccAKubernetesProvider_config_path (t * testing.T ) {
453+ func TestAccKubernetesProvider_config_path (t * testing.T ) {
454454
455- resource .ParallelTest (t , resource.TestCase {
456- PreCheck : func () { testAccPreCheck (t ); skipIfNotRunningInMinikube (t ) },
455+ resource .Test (t , resource.TestCase {
456+ PreCheck : func () { testAccPreCheck (t ); skipIfNotRunningInMinikube ( t ); unsetEnv (t ) },
457457 ProviderFactories : testAccProviderFactoriesInternal ,
458458 Steps : []resource.TestStep {
459459 {
460- Config : testAccKubernetesProvider_config_path (),
461- Check : resource .ComposeTestCheckFunc (
462- resource .TestCheckResourceAttr ("data.kubernetes_namespace.test" , "metadata.0.name" , "default" ),
460+ Config : testAccKubernetesProviderConfig (
461+ providerConfig_config_path ("~/.kube/config" ),
463462 ),
463+ Check : resource .TestCheckResourceAttr ("data.kubernetes_namespace.test" , "metadata.0.name" , "default" ),
464464 },
465465 },
466466 })
467467}
468468
469- func TestAccAKubernetesProvider_config_paths (t * testing.T ) {
469+ func TestAccKubernetesProvider_config_paths (t * testing.T ) {
470470 wantError := `"config_path": conflicts with config_paths`
471471
472- resource .ParallelTest (t , resource.TestCase {
473- PreCheck : func () { testAccPreCheck (t ); skipIfNotRunningInMinikube (t ) },
472+ resource .Test (t , resource.TestCase {
473+ PreCheck : func () { skipIfNotRunningInMinikube (t ); unsetEnv (t ) },
474474 ProviderFactories : testAccProviderFactoriesInternal ,
475475 Steps : []resource.TestStep {
476476 {
477- Config : testAccKubernetesProvider_config_paths (),
477+ Config : testAccKubernetesProviderConfig (
478+ providerConfig_config_paths ([]string {"~/.kube/config" , "~/.kube/config2" }),
479+ ),
480+ Check : resource .TestCheckResourceAttr ("data.kubernetes_namespace.test" , "metadata.0.name" , "default" ),
481+ },
482+ {
483+ Config : testAccKubernetesProviderConfig (
484+ providerConfig_config_path ("~/.kube/config" ) +
485+ providerConfig_config_paths ([]string {"~/.kube/config" , "~/.kube/config2" }),
486+ ),
478487 ExpectError : regexp .MustCompile (wantError ),
479488 },
480489 },
481490 })
482491}
483492
484- func testAccKubernetesProvider_config_path () string {
493+ // testAccKubernetesProviderConfig is used together with the providerConfig_* functions
494+ // to assemble a Kubernetes provider configuration with interchangeable options.
495+ func testAccKubernetesProviderConfig (providerConfig string ) string {
485496 return fmt .Sprintf (`provider "kubernetes" {
486- config_path = "~/.kube/config"
497+ %s
487498}
488499
489- # Required to initialize the provider.
490500data kubernetes_namespace "test" {
491501 metadata {
492502 name = "default"
493503 }
494504}
495- ` )
505+ ` , providerConfig )
496506}
497507
498- func testAccKubernetesProvider_config_paths () string {
499- return fmt .Sprintf (`provider "kubernetes" {
500- config_path = "~/.kube/config"
501- config_paths = ["~/.kube/config"]
502- # host = "https://192.168.39.129:8443"
503- # cluster_ca_certificate = file("~/.minikube/profiles/minikube/apiserver.crt")
504- # token = base64decode(file("~/.minikube/profiles/minikube/token"))
508+ func providerConfig_config_path (path string ) string {
509+ return fmt .Sprintf (`
510+ config_path = "%s"
511+ ` , path )
505512}
506513
507- # Required to initialize the provider.
508- data kubernetes_namespace "test" {
509- metadata {
510- name = "default"
511- }
514+ func providerConfig_config_paths (paths []string ) string {
515+ return fmt .Sprintf (`
516+ config_paths = [%q]
517+ ` , strings .Join (paths , ", " ))
512518}
513- ` )
519+
520+ func testAccKubernetesProviderConfig_token (token string ) string {
521+ return fmt .Sprintf (`
522+ token = %s
523+ ` , token )
524+ }
525+
526+ func testAccKubernetesProviderConfig_ca_cert (ca_cert string ) string {
527+ return fmt .Sprintf (`
528+ cluster_ca_certificate = %s
529+ ` , ca_cert )
530+ }
531+
532+ func testAccKubernetesProviderConfig_client_cert (client_cert string ) string {
533+ return fmt .Sprintf (`
534+ client_certificate = %s
535+ ` , client_cert )
536+ }
537+
538+ func testAccKubernetesProviderConfig_client_key (client_key string ) string {
539+ return fmt .Sprintf (`
540+ client_key = %s
541+ ` , client_key )
542+ }
543+
544+ func testAccKubernetesProviderConfig_host (host string ) string {
545+ return fmt .Sprintf (`
546+ host = %s
547+ ` , host )
548+ }
549+
550+ func testAccKubernetesProvider_exec (clusterName string ) string {
551+ return fmt .Sprintf (`
552+ exec {
553+ api_version = "client.authentication.k8s.io/v1alpha1"
554+ args = ["eks", "get-token", "--cluster-name", "%s"]
555+ command = "aws"
556+ }
557+ ` , clusterName )
514558}
0 commit comments