github.com/in4it/ecs-deploy@v0.0.42-0.20240508120354-ed77ff16df25/api/sort_test.go (about)

     1  package api
     2  
     3  import (
     4  	"sort"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/in4it/ecs-deploy/service"
     9  )
    10  
    11  func TestRuleConditionSort(t *testing.T) {
    12  	conditions := []*service.DeployRuleConditions{
    13  		{
    14  			Hostname: "test",
    15  		},
    16  		{
    17  			Hostname:    "test",
    18  			PathPattern: "/api",
    19  		},
    20  		{
    21  			Hostname:    "test",
    22  			PathPattern: "/api/v1",
    23  		},
    24  	}
    25  	conditionsSorted := []*service.DeployRuleConditions{
    26  		{
    27  			Hostname:    "test",
    28  			PathPattern: "/api/v1",
    29  		},
    30  		{
    31  			Hostname:    "test",
    32  			PathPattern: "/api",
    33  		},
    34  		{
    35  			Hostname: "test",
    36  		},
    37  	}
    38  	sort.Sort(ruleConditionSort(conditions))
    39  
    40  	if !cmp.Equal(conditions, conditionsSorted) {
    41  		t.Errorf("Conditions is not correctly sorted")
    42  	}
    43  }