github.com/hernad/nomad@v1.6.112/nomad/structs/consul_oss_test.go (about)

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