github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/commands/buildinfo/publish_test.go (about)

     1  package buildinfo
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  var envVars = map[string]string{"KeY": "key_val", "INClUdEd_VaR": "included_var", "EXCLUDED_pASSwoRd_var": "excluded_var"}
     9  
    10  func TestIncludeAllPattern(t *testing.T) {
    11  	includeFilter := createIncludeFilter("*")
    12  	filteredKeys, err := includeFilter(envVars)
    13  	if err != nil {
    14  		t.Error(err)
    15  	}
    16  
    17  	equals := reflect.DeepEqual(envVars, filteredKeys)
    18  	if !equals {
    19  		t.Error("expected:", envVars, "got:", filteredKeys)
    20  	}
    21  }
    22  
    23  func TestIncludePartial(t *testing.T) {
    24  	includeFilter := createIncludeFilter("*ED_V*;EXC*SwoRd_var")
    25  	filteredKeys, err := includeFilter(envVars)
    26  	if err != nil {
    27  		t.Error(err)
    28  	}
    29  
    30  	expected := map[string]string{"INClUdEd_VaR": "included_var", "EXCLUDED_pASSwoRd_var": "excluded_var"}
    31  	equals := reflect.DeepEqual(expected, filteredKeys)
    32  	if !equals {
    33  		t.Error("expected:", expected, "got:", filteredKeys)
    34  	}
    35  }
    36  
    37  func TestIncludePartialIgnoreCase(t *testing.T) {
    38  	includeFilter := createIncludeFilter("*Ed_v*")
    39  	filteredKeys, err := includeFilter(envVars)
    40  	if err != nil {
    41  		t.Error(err)
    42  	}
    43  
    44  	expected := map[string]string{"INClUdEd_VaR": "included_var"}
    45  	equals := reflect.DeepEqual(expected, filteredKeys)
    46  	if !equals {
    47  		t.Error("expected:", expected, "got:", filteredKeys)
    48  	}
    49  }
    50  
    51  func TestExcludePasswordsPattern(t *testing.T) {
    52  	excludeFilter := createExcludeFilter("*paSSword*;*seCrEt*;*kEy*;*token*")
    53  	filteredKeys, err := excludeFilter(envVars)
    54  	if err != nil {
    55  		t.Error(err)
    56  	}
    57  
    58  	expected := map[string]string{"INClUdEd_VaR": "included_var"}
    59  	equals := reflect.DeepEqual(expected, filteredKeys)
    60  	if !equals {
    61  		t.Error("expected:", expected, "got:", filteredKeys)
    62  	}
    63  }