github.com/sgoings/helm@v2.0.0-alpha.2.0.20170406211108-734e92851ac3+incompatible/pkg/storage/driver/records_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     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 driver // import "k8s.io/helm/pkg/storage/driver"
    18  
    19  import (
    20  	"testing"
    21  
    22  	rspb "k8s.io/helm/pkg/proto/hapi/release"
    23  )
    24  
    25  func TestRecordsAdd(t *testing.T) {
    26  	rs := records([]*record{
    27  		newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED)),
    28  		newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED)),
    29  	})
    30  
    31  	var tests = []struct {
    32  		desc string
    33  		key  string
    34  		ok   bool
    35  		rec  *record
    36  	}{
    37  		{
    38  			"add valid key",
    39  			"rls-a.v3",
    40  			false,
    41  			newRecord("rls-a.v3", releaseStub("rls-a", 3, "default", rspb.Status_SUPERSEDED)),
    42  		},
    43  		{
    44  			"add already existing key",
    45  			"rls-a.v1",
    46  			true,
    47  			newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_DEPLOYED)),
    48  		},
    49  	}
    50  
    51  	for _, tt := range tests {
    52  		if err := rs.Add(tt.rec); err != nil {
    53  			if !tt.ok {
    54  				t.Fatalf("failed: %q: %s\n", tt.desc, err)
    55  			}
    56  		}
    57  	}
    58  }
    59  
    60  func TestRecordsRemove(t *testing.T) {
    61  	var tests = []struct {
    62  		desc string
    63  		key  string
    64  		ok   bool
    65  	}{
    66  		{"remove valid key", "rls-a.v1", false},
    67  		{"remove invalid key", "rls-a.v", true},
    68  		{"remove non-existent key", "rls-z.v1", true},
    69  	}
    70  
    71  	rs := records([]*record{
    72  		newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED)),
    73  		newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED)),
    74  	})
    75  
    76  	for _, tt := range tests {
    77  		if r := rs.Remove(tt.key); r == nil {
    78  			if !tt.ok {
    79  				t.Fatalf("Failed to %q (key = %s). Expected nil, got %s",
    80  					tt.desc,
    81  					tt.key,
    82  					r,
    83  				)
    84  			}
    85  		}
    86  	}
    87  }