github.com/cnotch/ipchub@v1.1.0/provider/route/routetable_test.go (about)

     1  // Copyright (c) 2019,CAOHONGJU All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package route
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func Test_routetable(t *testing.T) {
    14  
    15  	t.Run("routetable", func(t *testing.T) {
    16  		Save(&Route{"/test/live1", "rtsp://localhost:5540/live1", false})
    17  		assert.Equal(t, 1, len(globalT.l))
    18  		r := Get("/test/live1")
    19  		assert.NotNil(t, r)
    20  		Save(&Route{"/easy/", "rtsp://localhost:5540/test", false})
    21  		assert.Equal(t, 2, len(globalT.l))
    22  		r = Match("/easy/live4")
    23  		assert.NotNil(t, r)
    24  		assert.Equal(t, "rtsp://localhost:5540/test/live4", r.URL)
    25  		Del("/test/live1")
    26  		Save(&Route{"/test/live1", "rtsp://localhost:5540/live1", false})
    27  		Save(&Route{"/test/live1", "rtsp://localhost:5540/live1", false})
    28  		Del("/test/live1")
    29  		Save(&Route{"/test/live1", "rtsp://localhost:5540/live1", false})
    30  		assert.Equal(t, 2, len(globalT.saves))
    31  		assert.Equal(t, 0, len(globalT.removes))
    32  		Flush()
    33  		assert.Equal(t, 0, len(globalT.saves))
    34  	})
    35  
    36  }