github.com/diafour/helm@v3.0.0-beta.3+incompatible/pkg/gates/gates_test.go (about)

     1  /*
     2  Copyright The Helm Authors.
     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  
    16  package gates
    17  
    18  import (
    19  	"os"
    20  	"testing"
    21  )
    22  
    23  const name string = "HELM_EXPERIMENTAL_FEATURE"
    24  
    25  func TestIsEnabled(t *testing.T) {
    26  	os.Unsetenv(name)
    27  	g := Gate(name)
    28  
    29  	if g.IsEnabled() {
    30  		t.Errorf("feature gate shows as available, but the environment variable %s was not set", name)
    31  	}
    32  
    33  	os.Setenv(name, "1")
    34  
    35  	if !g.IsEnabled() {
    36  		t.Errorf("feature gate shows as disabled, but the environment variable %s was set", name)
    37  	}
    38  }
    39  
    40  func TestError(t *testing.T) {
    41  	os.Unsetenv(name)
    42  	g := Gate(name)
    43  
    44  	if g.Error().Error() != "this feature has been marked as experimental and is not enabled by default. Please set HELM_EXPERIMENTAL_FEATURE=1 in your environment to use this feature" {
    45  		t.Errorf("incorrect error message. Received %s", g.Error().Error())
    46  	}
    47  }