github.com/boyter/gocodewalker@v1.3.2/go-gitignore/cache_test.go (about)

     1  // SPDX-License-Identifier: MIT
     2  
     3  package gitignore_test
     4  
     5  import (
     6  	"github.com/boyter/gocodewalker/go-gitignore"
     7  	"testing"
     8  )
     9  
    10  func TestCache(t *testing.T) {
    11  	// populate the cache with the defined tests
    12  	_cache := gitignore.NewCache()
    13  	for _k, _v := range _CACHETEST {
    14  		_cache.Set(_k, _v)
    15  	}
    16  
    17  	// attempt to retrieve the values from the cache
    18  	//		- if a GitIgnore instance is returned, ensure it is the correct
    19  	//		  instance, and not some other instance
    20  	for _k, _v := range _CACHETEST {
    21  		_found := _cache.Get(_k)
    22  		if _found != _v {
    23  			t.Errorf("cache Get() mismatch; expected %v, got %v",
    24  				_v, _found,
    25  			)
    26  		}
    27  	}
    28  
    29  	// ensure unknown cache keys return nil
    30  	for _, _k := range _CACHEUNKNOWN {
    31  		_found := _cache.Get(_k)
    32  		if _found != nil {
    33  			t.Errorf("cache.Get() unexpected return for key %q; "+
    34  				"expected nil, got %v",
    35  				_k, _found,
    36  			)
    37  		}
    38  	}
    39  
    40  	// ensure we can update the cache
    41  	_ignore := null()
    42  	for _k := range _CACHETEST {
    43  		_cache.Set(_k, _ignore)
    44  	}
    45  	for _k := range _CACHETEST {
    46  		_found := _cache.Get(_k)
    47  		if _found != _ignore {
    48  			t.Errorf("cache Get() mismatch; expected %v, got %v",
    49  				_ignore, _found,
    50  			)
    51  		}
    52  	}
    53  } // TestCache()