-
Notifications
You must be signed in to change notification settings - Fork 22
/
config_test.go
61 lines (49 loc) · 1.29 KB
/
config_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package config
import (
"errors"
"testing"
"time"
"github.com/fern4lvarez/piladb/pkg/uuid"
)
func TestNewConfig(t *testing.T) {
config := NewConfig()
if config.Values == nil {
t.Fatal(errors.New("Config is nil"))
}
inputOutput := []struct {
input, output interface{}
}{
{config.Values.Name, CONFIG},
{config.Values.ID, uuid.New(CONFIG)},
{len(config.Values.Stacks), 0},
}
for _, io := range inputOutput {
if io.input != io.output {
t.Errorf("got %v, expected %v", io.input, io.output)
}
}
}
func TestConfigGet(t *testing.T) {
config := NewConfig()
stackID := config.Values.CreateStack("foo", time.Now())
s, _ := config.Values.Stacks[stackID]
s.Push("bar")
expectedValue := s.Peek()
if value := config.Get("foo"); value != expectedValue {
t.Errorf("Values is %s, expected %s", value, expectedValue)
}
if value := config.Get("no-exist"); value != nil {
t.Errorf("Values is %s, expected nil", value)
}
}
func TestConfigSet(t *testing.T) {
config := NewConfig()
expectedValues := []string{"bar", "baz", "bam"}
for _, expectedValue := range expectedValues {
config.Set("foo", expectedValue)
s, _ := config.Values.Stacks[uuid.New(CONFIG+"foo")]
if value := s.Peek(); value != expectedValue {
t.Errorf("Values is %s, expected %s", value, expectedValue)
}
}
}