github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/pkg/fn/eval_test.go (about)

     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 fn
    16  
    17  import (
    18  	"errors"
    19  	"testing"
    20  
    21  	v1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
    22  	"github.com/google/go-cmp/cmp"
    23  )
    24  
    25  func TestNotFound(t *testing.T) {
    26  	var err error
    27  
    28  	fn := &v1.Function{Image: "foo"}
    29  	err = &NotFoundError{Function: *fn}
    30  
    31  	var notFoundErr *NotFoundError
    32  	if !errors.As(err, &notFoundErr) {
    33  		t.Fatalf("expected NotFoundError to satisfy errors.As")
    34  	}
    35  
    36  	if diff := cmp.Diff(notFoundErr.Function, *fn); diff != "" {
    37  		t.Fatalf("Unexpected result (-want, +got): %s", diff)
    38  	}
    39  
    40  	if diff := cmp.Diff(notFoundErr.Error(), "function \"foo\" not found"); diff != "" {
    41  		t.Fatalf("Unexpected result (-want, +got): %s", diff)
    42  	}
    43  }