...

Source file src/github.com/redhat-developer/odo/pkg/config/config_test.go

Documentation: github.com/redhat-developer/odo/pkg/config

     1  package config
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sethvargo/go-envconfig"
     7  )
     8  
     9  func TestDefaultValues(t *testing.T) {
    10  	cfg, err := GetConfigurationWith(envconfig.MapLookuper(nil))
    11  	if err != nil {
    12  		t.Errorf("Error is not expected: %v", err)
    13  	}
    14  
    15  	checkDefaultStringValue(t, "DockerCmd", cfg.DockerCmd, "docker")
    16  	checkDefaultStringValue(t, "PodmanCmd", cfg.PodmanCmd, "podman")
    17  	checkDefaultStringValue(t, "TelemetryCaller", cfg.TelemetryCaller, "")
    18  	checkDefaultBoolValue(t, "OdoExperimentalMode", cfg.OdoExperimentalMode, false)
    19  
    20  	// Use noinit to set non initialized value as nil instead of zero-value
    21  	checkNilString(t, "Globalodoconfig", cfg.Globalodoconfig)
    22  	checkNilString(t, "Globalodoconfig", cfg.Globalodoconfig)
    23  	checkNilString(t, "OdoDebugTelemetryFile", cfg.OdoDebugTelemetryFile)
    24  	checkNilBool(t, "OdoDisableTelemetry", cfg.OdoDisableTelemetry)
    25  	checkNilString(t, "OdoTrackingConsent", cfg.OdoTrackingConsent)
    26  
    27  }
    28  
    29  func checkDefaultStringValue(t *testing.T, fieldName string, field string, def string) {
    30  	if field != def {
    31  		t.Errorf("default value for %q should be %q but is %q", fieldName, def, field)
    32  	}
    33  
    34  }
    35  
    36  func checkDefaultBoolValue(t *testing.T, fieldName string, field bool, def bool) {
    37  	if field != def {
    38  		t.Errorf("default value for %q should be %v but is %v", fieldName, def, field)
    39  	}
    40  
    41  }
    42  
    43  func checkNilString(t *testing.T, fieldName string, field *string) {
    44  	if field != nil {
    45  		t.Errorf("value for non specified env var %q should be nil but is %q", fieldName, *field)
    46  
    47  	}
    48  }
    49  
    50  func checkNilBool(t *testing.T, fieldName string, field *bool) {
    51  	if field != nil {
    52  		t.Errorf("value for non specified env var %q should be nil but is %v", fieldName, *field)
    53  
    54  	}
    55  }
    56  

View as plain text