~rogpeppe/juju-core/254-txn-tester

« back to all changes in this revision

Viewing changes to testing/txntest/txntest_test.go

  • Committer: Roger Peppe
  • Date: 2013-03-25 08:59:24 UTC
  • Revision ID: roger.peppe@canonical.com-20130325085924-jdzjizz6ypepfm82
txntest: make args in to Params; add test actions

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package txntest_test
2
2
 
3
3
import (
 
4
        "errors"
 
5
        "fmt"
4
6
        . "launchpad.net/gocheck"
5
7
        "launchpad.net/juju-core/log"
6
8
        "launchpad.net/juju-core/testing"
7
9
        "launchpad.net/juju-core/testing/txntest"
 
10
        "strings"
8
11
        stdtesting "testing"
9
 
        "strings"
10
 
        "errors"
11
 
        "fmt"
12
12
)
13
13
 
14
14
func Test(t *stdtesting.T) {
26
26
        reset := func() txntest.DB {
27
27
                st.Run(&transaction{
28
28
                        assert: assertTrue,
29
 
                        run: opSet(""),
 
29
                        run:    opSet(""),
30
30
                })
31
31
                return st
32
32
        }
37
37
                }
38
38
                return nil
39
39
        }
40
 
                
41
 
        r := txntest.Run(reset, validate, createFooTester("x0"), createFooTester("x1"))
 
40
        r := txntest.Run(txntest.Params{
 
41
                Reset:    reset,
 
42
                Validate: validate,
 
43
                Ops: []func(txntest.DB) error{
 
44
                        createFooTester("x0"),
 
45
                        createFooTester("x1"),
 
46
                },
 
47
        })
42
48
        c.Check(r.ActionCount, Equals, int64(104))
43
49
        if len(r.Failures) != 0 {
44
50
                c.Errorf("%d failures: %v", len(r.Failures), r.Failures)
47
53
        c.Check(r.Complete, HasLen, 10)
48
54
}
49
55
 
50
 
var parseActionTests = []struct{
51
 
        s string
 
56
var parseActionTests = []struct {
 
57
        s   string
52
58
        err string
53
59
}{{
54
60
        s: "0",
59
65
}, {
60
66
        s: "0.1.0t.1t.1.1t.0*.1-",
61
67
}, {
62
 
        s: "",
 
68
        s:   "",
63
69
        err: `syntax error in ""`,
64
70
}, {
65
 
        s: "3.5d",
 
71
        s:   "3.5d",
66
72
        err: `bad number "5d" in "3.5d"`,
67
73
}, {
68
 
        s: "5..7",
 
74
        s:   "5..7",
69
75
        err: `syntax error in "5..7"`,
70
76
}}
71
77
 
93
99
        }
94
100
}
95
101
 
96
 
var errAlreadyExists = errors.New("already exists") 
 
102
var errAlreadyExists = errors.New("already exists")
97
103
 
98
104
func setFooVal(st *State, val string) error {
99
105
        log.Infof("setFooVal %q called", val)
125
131
func setFooTxn(st *State, val string) *transaction {
126
132
        return &transaction{
127
133
                assert: assertTrue,
128
 
                run: logOp("set foo to "+val, opReplace("foo{[^}]*}", "foo{"+val+"}")),
 
134
                run:    logOp("set foo to "+val, opReplace("foo{[^}]*}", "foo{"+val+"}")),
129
135
        }
130
136
}
131
137
 
135
141
                return fmt.Errorf("unexpected result of createFoo: %q", val)
136
142
        }
137
143
        return nil
138
 
}
 
 
b'\\ No newline at end of file'
 
144
}