Ejemplo n.º 1
0
				JustBeforeEach(func() {
					Expect(tx.Create(networkResource1)).To(Succeed())
					Expect(tx.Create(networkResource2)).To(Succeed())
					Expect(tx.Create(serverResource)).To(Succeed())
					Expect(tx.Commit()).To(Succeed())
					tx.Close()
					tx, err = dataStore.Begin()
					Expect(err).ToNot(HaveOccurred())
				})

				It("Returns the expected list", func() {
					list, num, err := tx.List(networkSchema, nil, nil)
					Expect(err).ToNot(HaveOccurred())
					Expect(num).To(Equal(uint64(2)))
					Expect(list).To(HaveLen(2))
					Expect(list[0]).To(util.MatchAsJSON(networkResource1))
					Expect(list[1]).To(util.MatchAsJSON(networkResource2))
					Expect(tx.Commit()).To(Succeed())
				})

				It("Returns the expected list with filter", func() {
					filter := map[string]interface{}{
						"tenant_id": []string{"red"},
					}
					list, num, err := tx.List(networkSchema, filter, nil)
					Expect(err).ToNot(HaveOccurred())
					Expect(num).To(Equal(uint64(1)))
					Expect(list).To(HaveLen(1))
					Expect(list[0]).To(util.MatchAsJSON(networkResource1))
					Expect(tx.Commit()).To(Succeed())
				})
Ejemplo n.º 2
0
				testURL("GET", networkPluralURL, adminTokenID, nil, http.StatusOK)
			})
		})

		It("should not authorize getting networks with no token", func() {
			testURL("GET", networkPluralURL, "", nil, http.StatusUnauthorized)
		})

		Context("having one network", func() {
			var result interface{}

			network := getNetwork("red", "red")

			BeforeEach(func() {
				result = testURL("POST", networkPluralURL, adminTokenID, network, http.StatusCreated)
				Expect(result).To(HaveKeyWithValue("network", util.MatchAsJSON(network)))
			})

			It("should get networks list", func() {
				result = testURL("GET", networkPluralURL, adminTokenID, nil, http.StatusOK)
				Expect(result).To(HaveKeyWithValue("networks", ConsistOf(util.MatchAsJSON(network))))
			})

			It("should get particular network", func() {
				result = testURL("GET", getNetworkSingularURL("red"), adminTokenID, nil, http.StatusOK)
				Expect(result).To(HaveKeyWithValue("network", util.MatchAsJSON(network)))
			})

			It("should not get invalid network", func() {
				testURL("GET", baseURL+"/v2.0/network/unknownID", adminTokenID, nil, http.StatusNotFound)
			})
Ejemplo n.º 3
0
				Describe("When invoked correctly", func() {
					Context("With transaction", func() {
						BeforeEach(func() {
							events["test"] = `
								context.networks = gohan_model_list(context, 'network', {});`
						})

						It("Correctly lists elements", func() {
							tx, err := testDB.Begin()
							Expect(err).NotTo(HaveOccurred())
							defer tx.Close()
							context["transaction"] = tx

							Expect(env.HandleEvent("test", context)).To(Succeed())
							Expect(tx.Commit()).To(Succeed())
							Expect(context).To(HaveKeyWithValue("networks", ConsistOf(util.MatchAsJSON(network1))))
						})
					})

					Context("With a string filter", func() {
						BeforeEach(func() {
							events["test"] = `
								console.log(context)
								context.networks = gohan_model_list(context, 'network', {'id': 'test1'});`
						})

						It("Correctly lists elements", func() {
							tx, err := testDB.Begin()
							Expect(err).NotTo(HaveOccurred())
							defer tx.Close()
							context["transaction"] = tx