コード例 #1
0
ファイル: pagination_test.go プロジェクト: masaki-saeki/gohan
func TestFromURLQueryErrors(t *testing.T) {
	RegisterTestingT(t)
	s := schema.NewSchema("foo", "foos", "Foo", "", "foo")
	s.Properties = append(s.Properties, schema.NewProperty("prop", "", "", "string", "", "", "", "", false, true, map[string]interface{}{}, "default"))

	values := url.Values{
		"limit":      []string{"a123"},
		"offset":     []string{"456"},
		"sort_key":   []string{"foo"},
		"sort_order": []string{"asc"},
	}
	pg, err := FromURLQuery(s, values)
	Expect(err).To(HaveOccurred(), "Got %v", pg)

	values.Set("limit", "123")
	values.Set("offset", "-1")
	pg, err = FromURLQuery(s, values)
	Expect(err).To(HaveOccurred(), "Got %v", pg)

	values.Set("offset", "123")
	values.Set("sort_key", "bad_key")
	pg, err = FromURLQuery(s, values)
	Expect(err).To(HaveOccurred(), "Got %v", pg)
}
コード例 #2
0
ファイル: sql_test.go プロジェクト: cloudwan/gohan
		Context("Relation column name", func() {
			It("Generate foreign key with default column name when relationColumn not available", func() {
				table, _ := sqlConn.GenTableDef(server, false)
				Expect(table).To(ContainSubstring("REFERENCES `networks`(id)"))
			})

			It("Generate foreign key with given column same as relationColumn from property", func() {
				server.Properties = append(server.Properties, schema.NewProperty(
					"test",
					"test",
					"",
					"test",
					"string",
					"subnet",
					"cidr",
					"",
					"varchar(255)",
					false,
					false,
					false,
					nil,
					nil,
					false,
				))
				table, _, err := sqlConn.AlterTableDef(server, false)
				Expect(err).ToNot(HaveOccurred())
				Expect(table).To(ContainSubstring("REFERENCES `subnets`(cidr)"))
			})
		})

		Context("With default cascade option", func() {
コード例 #3
0
ファイル: sql_test.go プロジェクト: vozhyk-/gohan
				Expect(table).To(ContainSubstring("REFERENCES `networks`(id) on delete cascade);"))
				table = sqlConn.GenTableDef(subnet, false)
				Expect(table).ToNot(ContainSubstring("REFERENCES `networks`(id) on delete cascade);"))
			})
		})

		Context("Properties modifed", func() {
			It("Generate proper alter table statements", func() {
				server.Properties = append(server.Properties, schema.NewProperty(
					"test",
					"test",
					"",
					"test",
					"string",
					"",
					"",
					"varchar(255)",
					false,
					false,
					false,
					nil,
					nil,
				))
				table, err := sqlConn.AlterTableDef(server, true)
				Expect(err).ToNot(HaveOccurred())
				Expect(table).To(ContainSubstring("alter table`servers` add (`test`varchar(255));"))
			})
		})
	})
})