github.com/TeaOSLab/EdgeNode@v1.3.8/internal/caches/list_file_kv_objects_test.go (about)

     1  // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package caches_test
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/caches"
     7  	"github.com/iwind/TeaGo/assert"
     8  	"testing"
     9  )
    10  
    11  func TestItemKVEncoder_EncodeField(t *testing.T) {
    12  	var a = assert.NewAssertion(t)
    13  
    14  	var encoder = caches.NewItemKVEncoder[*caches.Item]()
    15  	{
    16  		key, err := encoder.EncodeField(&caches.Item{
    17  			Key: "https://example.com/index.html",
    18  		}, "key")
    19  		if err != nil {
    20  			t.Fatal(err)
    21  		}
    22  		t.Log("key:", string(key))
    23  		a.IsTrue(string(key) == "https://example.com/index.html")
    24  	}
    25  
    26  	{
    27  		key, err := encoder.EncodeField(&caches.Item{
    28  			Key: "",
    29  		}, "wildKey")
    30  		if err != nil {
    31  			t.Fatal(err)
    32  		}
    33  		t.Log("key:", string(key))
    34  		a.IsTrue(string(key) == "")
    35  	}
    36  
    37  	{
    38  		key, err := encoder.EncodeField(&caches.Item{
    39  			Key: "example.com/index.html",
    40  		}, "wildKey")
    41  		if err != nil {
    42  			t.Fatal(err)
    43  		}
    44  		t.Log("key:", string(key))
    45  		a.IsTrue(string(key) == "example.com/index.html")
    46  	}
    47  
    48  	{
    49  		key, err := encoder.EncodeField(&caches.Item{
    50  			Key: "https://example.com/index.html",
    51  		}, "wildKey")
    52  		if err != nil {
    53  			t.Fatal(err)
    54  		}
    55  		t.Log("key:", string(key))
    56  		a.IsTrue(string(key) == "https://*.com/index.html")
    57  	}
    58  
    59  	{
    60  		key, err := encoder.EncodeField(&caches.Item{
    61  			Key: "https://www.example.com/index.html",
    62  		}, "wildKey")
    63  		if err != nil {
    64  			t.Fatal(err)
    65  		}
    66  		t.Log("key:", string(key))
    67  		a.IsTrue(string(key) == "https://*.example.com/index.html")
    68  	}
    69  }