github.com/kubesphere/s2irun@v3.2.1+incompatible/pkg/scripts/environment_test.go (about)

     1  package scripts
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kubesphere/s2irun/pkg/api"
     7  )
     8  
     9  func TestConvertEnvironmentList(t *testing.T) {
    10  	testEnv := api.EnvironmentList{
    11  		{Name: "Key1", Value: "Value1"},
    12  		{Name: "Key2", Value: "Value2"},
    13  		{Name: "Key3", Value: "Value3"},
    14  		{Name: "Key4", Value: "Value=4"},
    15  		{Name: "Key5", Value: "Value,5"},
    16  	}
    17  	result := ConvertEnvironmentList(testEnv)
    18  	expected := []string{"Key1=Value1", "Key2=Value2", "Key3=Value3", "Key4=Value=4", "Key5=Value,5"}
    19  	if !equalArrayContents(result, expected) {
    20  		t.Errorf("Unexpected result. Expected: %#v. Actual: %#v",
    21  			expected, result)
    22  	}
    23  }
    24  
    25  func equalArrayContents(a []string, b []string) bool {
    26  	if len(a) != len(b) {
    27  		return false
    28  	}
    29  	for _, e := range a {
    30  		found := false
    31  		for _, f := range b {
    32  			if f == e {
    33  				found = true
    34  				break
    35  			}
    36  		}
    37  		if !found {
    38  			return false
    39  		}
    40  	}
    41  	return true
    42  }