github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/commands/fn/doc/cmdfndoc_test.go (about)

     1  // Copyright 2021 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 doc_test
    16  
    17  import (
    18  	"bytes"
    19  	"testing"
    20  
    21  	"github.com/GoogleContainerTools/kpt/commands/fn/doc"
    22  	"github.com/GoogleContainerTools/kpt/internal/printer/fake"
    23  	"sigs.k8s.io/kustomize/kyaml/testutil"
    24  )
    25  
    26  // TestDesc_Execute tests happy path for Describe command.
    27  func TestFnDoc(t *testing.T) {
    28  	type testcase struct {
    29  		image     string
    30  		expectErr string
    31  	}
    32  	testcases := []testcase{
    33  		{
    34  			image: "gcr.io/kpt-fn/set-namespace:v0.1.1",
    35  		},
    36  		{
    37  			image:     "gcr.io/kpt-fn/set-namespace:v0.1.0",
    38  			expectErr: "please ensure the container has an entrypoint and it supports --help flag",
    39  		},
    40  		{
    41  			image:     "",
    42  			expectErr: "image must be specified",
    43  		},
    44  	}
    45  
    46  	for _, tc := range testcases {
    47  		b := &bytes.Buffer{}
    48  		runner := doc.NewRunner(fake.CtxWithPrinter(b, b), "kpt")
    49  		runner.Image = tc.image
    50  		err := runner.Command.Execute()
    51  		if tc.expectErr == "" {
    52  			testutil.AssertNoError(t, err)
    53  		} else {
    54  			testutil.AssertErrorContains(t, err, tc.expectErr)
    55  		}
    56  	}
    57  }