github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/serviceregistration/service_registration_test.go (about)

     1  package serviceregistration
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/nomad/nomad/structs"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestAllocRegistration_Copy(t *testing.T) {
    11  	testCases := []struct {
    12  		inputAllocRegistration *AllocRegistration
    13  		name                   string
    14  	}{
    15  		{
    16  			inputAllocRegistration: &AllocRegistration{
    17  				Tasks: map[string]*ServiceRegistrations{},
    18  			},
    19  			name: "empty tasks map",
    20  		},
    21  		{
    22  			inputAllocRegistration: &AllocRegistration{
    23  				Tasks: map[string]*ServiceRegistrations{
    24  					"cache": {
    25  						Services: map[string]*ServiceRegistration{
    26  							"redis-db": {
    27  								ServiceID: "service-id-1",
    28  								CheckIDs: map[string]struct{}{
    29  									"check-id-1": {},
    30  									"check-id-2": {},
    31  									"check-id-3": {},
    32  								},
    33  								CheckOnUpdate: map[string]string{
    34  									"check-id-1": structs.OnUpdateIgnore,
    35  									"check-id-2": structs.OnUpdateRequireHealthy,
    36  									"check-id-3": structs.OnUpdateIgnoreWarn,
    37  								},
    38  							},
    39  						},
    40  					},
    41  				},
    42  			},
    43  			name: "non-empty tasks map",
    44  		},
    45  	}
    46  
    47  	for _, tc := range testCases {
    48  		t.Run(tc.name, func(t *testing.T) {
    49  			actualOutput := tc.inputAllocRegistration.Copy()
    50  			require.Equal(t, tc.inputAllocRegistration, actualOutput)
    51  		})
    52  	}
    53  }