-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathstrategic_patch_test.go
More file actions
81 lines (67 loc) · 2.06 KB
/
strategic_patch_test.go
File metadata and controls
81 lines (67 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build acceptance
// +build acceptance
package acceptance
import (
"context"
"fmt"
"strings"
"testing"
"time"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/terraform-provider-kubernetes/manifest/provider"
)
func TestKubernetesManifest_StrategicPatch(t *testing.T) {
ctx := context.Background()
reattachInfo, err := provider.ServeTest(ctx, hclog.Default(), t)
if err != nil {
t.Errorf("Failed to create provider instance: %q", err)
}
kind := "Strategic"
plural := "strategics"
group := "terraform.io"
version := "v1"
groupVersion := group + "/" + version
crd := fmt.Sprintf("%s.%s", plural, group)
name := strings.ToLower(randName())
namespace := "default"
tfvars := TFVARS{
"name": name,
"namespace": namespace,
"kind": kind,
"plural": plural,
"group": group,
"group_version": groupVersion,
"cr_version": version,
}
step1 := tfhelper.RequireNewWorkingDir(ctx, t)
step1.SetReattachInfo(ctx, reattachInfo)
defer func() {
step1.Destroy(ctx)
step1.Close()
k8shelper.AssertResourceDoesNotExist(t, "apiextensions.k8s.io/v1", "customresourcedefinitions", crd)
}()
crdTfConfig := loadTerraformConfig(t, "StrategicPatch/crd.tf", tfvars)
step1.SetConfig(ctx, string(crdTfConfig))
step1.Init(ctx)
step1.Apply(ctx)
k8shelper.AssertResourceExists(t, "apiextensions.k8s.io/v1", "customresourcedefinitions", crd)
// wait for API to finish ingesting the CRD
time.Sleep(5 * time.Second) //lintignore:R018
reattachInfo2, err := provider.ServeTest(ctx, hclog.Default(), t)
if err != nil {
t.Errorf("Failed to create additional provider instance: %q", err)
}
step2 := tfhelper.RequireNewWorkingDir(ctx, t)
step2.SetReattachInfo(ctx, reattachInfo2)
defer func() {
step2.Destroy(ctx)
step2.Close()
k8shelper.AssertResourceDoesNotExist(t, groupVersion, kind, name)
}()
tfconfig := loadTerraformConfig(t, "StrategicPatch/strategic_patch.tf", tfvars)
step2.SetConfig(ctx, string(tfconfig))
step2.Init(ctx)
step2.Apply(ctx)
}