github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/kubernetes/debugging/transform_netcore_test.go (about)

     1  /*
     2  Copyright 2021 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package debugging
    18  
    19  import (
    20  	"testing"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  
    24  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/debug"
    25  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/debug/types"
    26  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/debugging/adapter"
    27  	"github.com/GoogleContainerTools/skaffold/testutil"
    28  )
    29  
    30  func TestNetcoreTransformerApply(t *testing.T) {
    31  	tests := []struct {
    32  		description   string
    33  		containerSpec v1.Container
    34  		configuration debug.ImageConfiguration
    35  		shouldErr     bool
    36  		result        v1.Container
    37  		debugConfig   types.ContainerDebugConfiguration
    38  		image         string
    39  	}{
    40  		{
    41  			description:   "empty",
    42  			containerSpec: v1.Container{},
    43  			configuration: debug.ImageConfiguration{},
    44  
    45  			debugConfig: types.ContainerDebugConfiguration{Runtime: "netcore"},
    46  			image:       "netcore",
    47  			shouldErr:   false,
    48  		},
    49  		{
    50  			description:   "basic",
    51  			containerSpec: v1.Container{},
    52  			configuration: debug.ImageConfiguration{Entrypoint: []string{"dotnet", "myapp.dll"}},
    53  
    54  			result:      v1.Container{},
    55  			debugConfig: types.ContainerDebugConfiguration{Runtime: "netcore"},
    56  			image:       "netcore",
    57  			shouldErr:   false,
    58  		},
    59  	}
    60  	var identity debug.PortAllocator = func(port int32) int32 {
    61  		return port
    62  	}
    63  	for _, test := range tests {
    64  		testutil.Run(t, test.description, func(t *testutil.T) {
    65  			adapter := adapter.NewAdapter(&test.containerSpec)
    66  			config, image, err := debug.NewNetcoreTransformer().Apply(adapter, test.configuration, identity, nil)
    67  			adapter.Apply()
    68  
    69  			t.CheckError(test.shouldErr, err)
    70  			t.CheckDeepEqual(test.result, test.containerSpec)
    71  			t.CheckDeepEqual(test.debugConfig, config)
    72  			t.CheckDeepEqual(test.image, image)
    73  		})
    74  	}
    75  }