go-micro.dev/v5@v5.12.0/cache/options_test.go (about) 1 package cache 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func TestOptions(t *testing.T) { 9 testData := map[string]struct { 10 set bool 11 expiration time.Duration 12 items map[string]Item 13 }{ 14 "DefaultOptions": {false, DefaultExpiration, map[string]Item{}}, 15 "ModifiedOptions": {true, time.Second, map[string]Item{"test": {"hello go-micro", 0}}}, 16 } 17 18 for k, d := range testData { 19 t.Run(k, func(t *testing.T) { 20 var opts Options 21 22 if d.set { 23 opts = NewOptions( 24 Expiration(d.expiration), 25 Items(d.items), 26 ) 27 } else { 28 opts = NewOptions() 29 } 30 31 // test options 32 for _, o := range []Options{opts} { 33 if o.Expiration != d.expiration { 34 t.Fatalf("Expected expiration '%v', got '%v'", d.expiration, o.Expiration) 35 } 36 37 if o.Items["test"] != d.items["test"] { 38 t.Fatalf("Expected items %#v, got %#v", d.items, o.Items) 39 } 40 } 41 }) 42 } 43 }