No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

47 líneas
1.1 KiB

  1. // Copyright 2016 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package atomiccache
  15. import (
  16. "fmt"
  17. "testing"
  18. )
  19. func TestGet(t *testing.T) {
  20. var c Cache
  21. called := false
  22. get := func(k interface{}) interface{} {
  23. return c.Get(k, func() interface{} {
  24. called = true
  25. return fmt.Sprintf("v%d", k)
  26. })
  27. }
  28. got := get(1)
  29. if want := "v1"; got != want {
  30. t.Errorf("got %v, want %v", got, want)
  31. }
  32. if !called {
  33. t.Error("getter not called, expected a call")
  34. }
  35. called = false
  36. got = get(1)
  37. if want := "v1"; got != want {
  38. t.Errorf("got %v, want %v", got, want)
  39. }
  40. if called {
  41. t.Error("getter unexpectedly called")
  42. }
  43. }