Skip to content

Commit 84e62d3

Browse files
committed
wip
1 parent d6156c5 commit 84e62d3

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

kubernetes/provider_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"regexp"
910
"strings"
1011
"testing"
1112

@@ -166,6 +167,9 @@ func getEnv() *currentEnv {
166167
return e
167168
}
168169

170+
// testAccPreCheck verifies and sets required provider testing configuration
171+
// This PreCheck function should be present in every acceptance test. It allows
172+
// test configurations to omit a provider configuration
169173
func testAccPreCheck(t *testing.T) {
170174
ctx := context.TODO()
171175
hasFileCfg := (os.Getenv("KUBE_CTX_AUTH_INFO") != "" && os.Getenv("KUBE_CTX_CLUSTER") != "") ||
@@ -436,3 +440,75 @@ func requiredProviders() string {
436440
}
437441
`)
438442
}
443+
444+
// testAccProviderFactoriesInternal is a factory used for provider configuration testing.
445+
// This should only be used for TestAccKubernetesProvider_ tests which need to
446+
// reference the provider instance itself. Other testing should use testAccProviderFactories.
447+
var testAccProviderFactoriesInternal = map[string]func() (*schema.Provider, error){
448+
"kubernetes": func() (*schema.Provider, error) {
449+
return Provider(), nil
450+
},
451+
}
452+
453+
func TestAccAKubernetesProvider_config_path(t *testing.T) {
454+
455+
resource.ParallelTest(t, resource.TestCase{
456+
PreCheck: func() { testAccPreCheck(t); skipIfNotRunningInMinikube(t) },
457+
ProviderFactories: testAccProviderFactoriesInternal,
458+
Steps: []resource.TestStep{
459+
{
460+
Config: testAccKubernetesProvider_config_path(),
461+
Check: resource.ComposeTestCheckFunc(
462+
resource.TestCheckResourceAttr("data.kubernetes_namespace.test", "metadata.0.name", "default"),
463+
),
464+
},
465+
},
466+
})
467+
}
468+
469+
func TestAccAKubernetesProvider_config_paths(t *testing.T) {
470+
wantError := `"config_path": conflicts with config_paths`
471+
472+
resource.ParallelTest(t, resource.TestCase{
473+
PreCheck: func() { testAccPreCheck(t); skipIfNotRunningInMinikube(t) },
474+
ProviderFactories: testAccProviderFactoriesInternal,
475+
Steps: []resource.TestStep{
476+
{
477+
Config: testAccKubernetesProvider_config_paths(),
478+
ExpectError: regexp.MustCompile(wantError),
479+
},
480+
},
481+
})
482+
}
483+
484+
func testAccKubernetesProvider_config_path() string {
485+
return fmt.Sprintf(`provider "kubernetes" {
486+
config_path = "~/.kube/config"
487+
}
488+
489+
# Required to initialize the provider.
490+
data kubernetes_namespace "test" {
491+
metadata {
492+
name = "default"
493+
}
494+
}
495+
`)
496+
}
497+
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"))
505+
}
506+
507+
# Required to initialize the provider.
508+
data kubernetes_namespace "test" {
509+
metadata {
510+
name = "default"
511+
}
512+
}
513+
`)
514+
}

0 commit comments

Comments
 (0)