github.com/kiali/kiali@v1.84.0/business/checkers/gateways/port_checker_test.go (about)

     1  package gateways
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/kiali/kiali/config"
     9  	"github.com/kiali/kiali/models"
    10  	"github.com/kiali/kiali/tests/data"
    11  	"github.com/kiali/kiali/tests/testutils/validations"
    12  )
    13  
    14  func TestValidPortDefinition(t *testing.T) {
    15  	conf := config.NewConfig()
    16  	config.Set(conf)
    17  
    18  	assert := assert.New(t)
    19  
    20  	gw := data.AddServerToGateway(
    21  		data.CreateServer([]string{"localhost"}, uint32(80), "http", "http"),
    22  		data.CreateEmptyGateway("valid-gw", "test", map[string]string{"istio": "ingressgateway"}),
    23  	)
    24  	pc := PortChecker{Gateway: gw}
    25  	vals, valid := pc.Check()
    26  	assert.True(valid)
    27  	assert.Empty(vals)
    28  }
    29  
    30  func TestInvalidPortDefinition(t *testing.T) {
    31  	conf := config.NewConfig()
    32  	config.Set(conf)
    33  
    34  	assert := assert.New(t)
    35  
    36  	gw := data.AddServerToGateway(
    37  		data.CreateServer([]string{"localhost"}, uint32(80), "http", "http2"),
    38  		data.CreateEmptyGateway("notvalid-gw", "test", map[string]string{"istio": "ingressgateway"}),
    39  	)
    40  	pc := PortChecker{Gateway: gw}
    41  	vals, valid := pc.Check()
    42  	assert.False(valid)
    43  	assert.NotEmpty(vals)
    44  	assert.Equal(models.ErrorSeverity, vals[0].Severity)
    45  	assert.NoError(validations.ConfirmIstioCheckMessage("port.name.mismatch", vals[0]))
    46  	assert.Equal("spec/servers[0]/port/name", vals[0].Path)
    47  }