github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/consul_oss_test.go (about)

     1  //go:build !ent
     2  // +build !ent
     3  
     4  package structs
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/hashicorp/nomad/ci"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestJob_ConfigEntries(t *testing.T) {
    14  	ci.Parallel(t)
    15  
    16  	ingress := &ConsulConnect{
    17  		Gateway: &ConsulGateway{
    18  			Ingress: new(ConsulIngressConfigEntry),
    19  		},
    20  	}
    21  
    22  	terminating := &ConsulConnect{
    23  		Gateway: &ConsulGateway{
    24  			Terminating: new(ConsulTerminatingConfigEntry),
    25  		},
    26  	}
    27  
    28  	j := &Job{
    29  		TaskGroups: []*TaskGroup{{
    30  			Name:   "group1",
    31  			Consul: nil,
    32  			Services: []*Service{{
    33  				Name:    "group1-service1",
    34  				Connect: ingress,
    35  			}, {
    36  				Name:    "group1-service2",
    37  				Connect: nil,
    38  			}, {
    39  				Name:    "group1-service3",
    40  				Connect: terminating,
    41  			}},
    42  		}, {
    43  			Name:   "group2",
    44  			Consul: nil,
    45  			Services: []*Service{{
    46  				Name:    "group2-service1",
    47  				Connect: ingress,
    48  			}},
    49  		}, {
    50  			Name:   "group3",
    51  			Consul: &Consul{Namespace: "apple"},
    52  			Services: []*Service{{
    53  				Name:    "group3-service1",
    54  				Connect: ingress,
    55  			}},
    56  		}, {
    57  			Name:   "group4",
    58  			Consul: &Consul{Namespace: "apple"},
    59  			Services: []*Service{{
    60  				Name:    "group4-service1",
    61  				Connect: ingress,
    62  			}, {
    63  				Name:    "group4-service2",
    64  				Connect: terminating,
    65  			}},
    66  		}, {
    67  			Name:   "group5",
    68  			Consul: &Consul{Namespace: "banana"},
    69  			Services: []*Service{{
    70  				Name:    "group5-service1",
    71  				Connect: ingress,
    72  			}},
    73  		}},
    74  	}
    75  
    76  	exp := map[string]*ConsulConfigEntries{
    77  		// in OSS, consul namespace is not supported
    78  		"": {
    79  			Ingress: map[string]*ConsulIngressConfigEntry{
    80  				"group1-service1": new(ConsulIngressConfigEntry),
    81  				"group2-service1": new(ConsulIngressConfigEntry),
    82  				"group3-service1": new(ConsulIngressConfigEntry),
    83  				"group4-service1": new(ConsulIngressConfigEntry),
    84  				"group5-service1": new(ConsulIngressConfigEntry),
    85  			},
    86  			Terminating: map[string]*ConsulTerminatingConfigEntry{
    87  				"group1-service3": new(ConsulTerminatingConfigEntry),
    88  				"group4-service2": new(ConsulTerminatingConfigEntry),
    89  			},
    90  		},
    91  	}
    92  
    93  	entries := j.ConfigEntries()
    94  	require.EqualValues(t, exp, entries)
    95  }