DJDNS / go-deje

Golang library for DEJE Next, a protocol/technology for decentralized document hosting and concurrent editing.
GNU Lesser General Public License v2.1
8 stars 0 forks source link

Use anon structs in tests where applicable #39

Open MaddieM4 opened 10 years ago

MaddieM4 commented 10 years ago

A useful testing pattern, which apparently is common knowledge in the Go community but new to me, is the use of anon structs in tests.

func TestXYZ(t *testing.T) {
    tests := []struct{
        Description string
        Status int
        ExpectedOutput string
    }{
        {
            Description: "Foo does bar",
            Status: 5,
            ExpectedOutput: "xyzxyzxyzxyzxyz",
        },
        { ... },
    }
}

There are a few tests, particularly in the TimestampTracker tests (IIRC), where this would have been much more idiomatic than a named type. Research where this makes sense, and rewrite the tests to use this style.