...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/krmtotf/testkrmtotf.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/krmtotf

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package testkrmtotf
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/core/v1alpha1"
    22  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf"
    23  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/servicemapping/servicemappingloader"
    24  
    25  	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
    26  	"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
    27  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
    28  	"sigs.k8s.io/controller-runtime/pkg/client"
    29  )
    30  
    31  func NewKRMResource(t *testing.T, u *unstructured.Unstructured, sm *v1alpha1.ServiceMapping, tfProvider *schema.Provider) *krmtotf.Resource {
    32  	t.Helper()
    33  	krmResource, err := krmtotf.NewResource(u, sm, tfProvider)
    34  	if err != nil {
    35  		t.Fatalf("error creating new krm resource: %v", err)
    36  	}
    37  	return krmResource
    38  }
    39  
    40  func FetchLiveState(t *testing.T, resource *krmtotf.Resource, provider *schema.Provider, kubeClient client.Client, smLoader *servicemappingloader.ServiceMappingLoader) *terraform.InstanceState {
    41  	t.Helper()
    42  	liveState, err := krmtotf.FetchLiveState(context.Background(), resource, provider, kubeClient, smLoader)
    43  	if err != nil {
    44  		t.Fatalf("error fetching live state: %v", err)
    45  	}
    46  	return liveState
    47  }
    48  

View as plain text