Permalink
Browse files

Make convert test fixtures less sloppy

There were some compile errors and other odds and ends that I didn't find
when I was initially writing these. The whole point of this exercise was to
enable other people to write clean, clear tests with Ginkgo, so there's no
value in writing the tests for this feature in such a slapdash fashion.
  • Loading branch information...
1 parent 5aab1d4 commit 0cccf6e8b369fece49677e0442245c88067d81b7 @tjarratt tjarratt committed Feb 10, 2014
@@ -5,7 +5,8 @@ import (
)
func TestSomethingLessImportant(t *testing.T) {
- somethingImportant(t, &"hello!")
+ strp := "hello!"
+ somethingImportant(t, &strp)
}
func somethingImportant(t *testing.T, message *string) {
@@ -1,20 +0,0 @@
-package tmp
-
-import (
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-type UselessStruct struct {
- ImportantField string
-}
-
-func init() {
- Describe("Testing with ginkgo", func() {
- It("TestSomethingImportant", func() {
-
- whatever := &UselessStruct{}
- t.Fail(whatever.ImportantField != "SECRET_PASSWORD")
- })
- })
-}
@@ -10,5 +10,7 @@ type UselessStruct struct {
func TestSomethingImportant(t *testing.T) {
whatever := &UselessStruct{}
- t.Fail(whatever.ImportantField != "SECRET_PASSWORD")
+ if whatever.ImportantField != "SECRET_PASSWORD" {
+ t.Fail()
+ }
}
@@ -11,17 +11,25 @@ type UselessStruct struct {
var testFunc = func(t *testing.T, arg *string) {}
+func assertEqual(t *testing.T, arg1, arg2 interface{}) {
+ if arg1 != arg2 {
+ t.Fail()
+ }
+}
+
func TestSomethingImportant(t *testing.T) {
whatever := &UselessStruct{
T: t,
- ImportantField: "twisty maze of passages",
+ ImportantField: "SECRET_PASSWORD",
}
- app := "string value"
- something := &UselessStruct{ImportantField: app}
+ something := &UselessStruct{ImportantField: "string value"}
+ assertEqual(t, whatever.ImportantField, "SECRET_PASSWORD")
+ assertEqual(t, something.ImportantField, "string value")
- t.Fail(whatever.ImportantField != "SECRET_PASSWORD")
- assert.Equal(t, whatever.ImportantField, "SECRET_PASSWORD")
var foo = func(t *testing.T) {}
- foo()
- testFunc(t, "something")
+ foo(t)
+
+ strp := "something"
+ testFunc(t, &strp)
+ t.Fail()
}
@@ -10,7 +10,8 @@ func somethingImportant(t GinkgoTestingT, message *string) {
func init() {
Describe("Testing with Ginkgo", func() {
It("something less important", func() {
- somethingImportant(GinkgoT(), &"hello!")
+ strp := "hello!"
+ somethingImportant(GinkgoT(), &strp)
})
})
}
@@ -13,7 +13,9 @@ func init() {
It("something important", func() {
whatever := &UselessStruct{}
- GinkgoT().Fail(whatever.ImportantField != "SECRET_PASSWORD")
+ if whatever.ImportantField != "SECRET_PASSWORD" {
+ GinkgoT().Fail()
+ }
})
})
}
@@ -11,21 +11,29 @@ type UselessStruct struct {
var testFunc = func(t GinkgoTestingT, arg *string) {}
+func assertEqual(t GinkgoTestingT, arg1, arg2 interface{}) {
+ if arg1 != arg2 {
+ t.Fail()
+ }
+}
func init() {
Describe("Testing with Ginkgo", func() {
It("something important", func() {
whatever := &UselessStruct{
T: GinkgoT(),
- ImportantField: "twisty maze of passages",
+ ImportantField: "SECRET_PASSWORD",
}
- app := "string value"
- something := &UselessStruct{ImportantField: app}
- GinkgoT().Fail(whatever.ImportantField != "SECRET_PASSWORD")
- assert.Equal(GinkgoT(), whatever.ImportantField, "SECRET_PASSWORD")
+ something := &UselessStruct{ImportantField: "string value"}
+ assertEqual(GinkgoT(), whatever.ImportantField, "SECRET_PASSWORD")
+ assertEqual(GinkgoT(), something.ImportantField, "string value")
+
var foo = func(t GinkgoTestingT) {}
- foo()
- testFunc(GinkgoT(), "something")
+ foo(GinkgoT())
+
+ strp := "something"
+ testFunc(GinkgoT(), &strp)
+ GinkgoT().Fail()
})
})
}

0 comments on commit 0cccf6e

Please sign in to comment.