github.com/x-helm/helm@v3.0.0-beta.3+incompatible/pkg/releaseutil/filter_test.go (about)

     1  /*
     2  Copyright The Helm 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 releaseutil // import "helm.sh/helm/pkg/releaseutil"
    18  
    19  import (
    20  	"testing"
    21  
    22  	rspb "helm.sh/helm/pkg/release"
    23  )
    24  
    25  func TestFilterAny(t *testing.T) {
    26  	ls := Any(StatusFilter(rspb.StatusUninstalled)).Filter(releases)
    27  	if len(ls) != 2 {
    28  		t.Fatalf("expected 2 results, got '%d'", len(ls))
    29  	}
    30  
    31  	r0, r1 := ls[0], ls[1]
    32  	switch {
    33  	case r0.Info.Status != rspb.StatusUninstalled:
    34  		t.Fatalf("expected UNINSTALLED result, got '%s'", r1.Info.Status.String())
    35  	case r1.Info.Status != rspb.StatusUninstalled:
    36  		t.Fatalf("expected UNINSTALLED result, got '%s'", r1.Info.Status.String())
    37  	}
    38  }
    39  
    40  func TestFilterAll(t *testing.T) {
    41  	fn := FilterFunc(func(rls *rspb.Release) bool {
    42  		// true if not uninstalled and version < 4
    43  		v0 := !StatusFilter(rspb.StatusUninstalled).Check(rls)
    44  		v1 := rls.Version < 4
    45  		return v0 && v1
    46  	})
    47  
    48  	ls := All(fn).Filter(releases)
    49  	if len(ls) != 1 {
    50  		t.Fatalf("expected 1 result, got '%d'", len(ls))
    51  	}
    52  
    53  	switch r0 := ls[0]; {
    54  	case r0.Version == 4:
    55  		t.Fatal("got release with status revision 4")
    56  	case r0.Info.Status == rspb.StatusUninstalled:
    57  		t.Fatal("got release with status UNINSTALLED")
    58  	}
    59  }