forked from golang-bristol/beer-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_mem_test.go
44 lines (36 loc) · 1.09 KB
/
storage_mem_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"testing"
"time"
model "github.com/golang-bristol/beer-model"
)
func TestSaveBeer(t *testing.T) {
storage := new(StorageMemory)
sampleBeer := model.Beer{
ID: 1,
Name: "Pliny the Elder",
Brewery: "Russian River Brewing Company",
Abv: 8,
ShortDesc: "Pliny the Elder is brewed with Amarillo, " +
"Centennial, CTZ, and Simcoe hops. It is well-balanced with " +
"malt, hops, and alcohol, slightly bitter with a fresh hop " +
"aroma of floral, citrus, and pine.",
Created: time.Date(2017, time.October, 24, 22, 6, 0, 0, time.UTC),
}
storage.SaveBeer(sampleBeer)
if len(storage.cellar) == 0 {
t.Errorf("Expected sample beer to be added to storage list.")
t.FailNow()
}
sampleBeerChange := sampleBeer
sampleBeerChange.Name = "Not a beer name"
storage.SaveBeer(sampleBeerChange)
if len(storage.cellar) > 1 {
t.Errorf("Expected sample beer to be updated instead of creating another entry.")
t.FailNow()
}
if storage.cellar[0].Name == sampleBeer.Name {
t.Errorf("Expected sample beer name to be updated with new name.")
t.FailNow()
}
}