コード例 #1
0
ファイル: server_test.go プロジェクト: gitter-badger/gohan
	})

	Describe("Sync", func() {
		It("should work", func() {
			manager := schema.GetManager()
			networkSchema, _ := manager.Schema("network")
			network := getNetwork("Red", "red")
			networkResource, err := manager.LoadResource("network", network)
			Expect(err).ToNot(HaveOccurred())
			testDB1 := &srv.DbSyncWrapper{DB: testDB}
			tx, _ := testDB1.Begin()
			tx.Create(networkResource)
			tx.Commit()
			tx.Close()

			err = server.Sync()
			Expect(err).ToNot(HaveOccurred())

			sync := etcd.NewSync(nil)

			networkResource1, err := sync.Fetch(networkResource.Path())
			Expect(err).ToNot(HaveOccurred())
			Expect(networkResource1).ToNot(BeNil())

			tx, _ = testDB1.Begin()
			tx.Delete(networkSchema, networkResource.ID())
			tx.Commit()
			tx.Close()

			err = server.Sync()
			Expect(err).ToNot(HaveOccurred())
コード例 #2
0
ファイル: server_test.go プロジェクト: masaki-saeki/gohan
	Describe("Sync", func() {
		It("should work", func() {
			manager := schema.GetManager()
			networkSchema, _ := manager.Schema("network")
			network := getNetwork("Red", "red")
			networkResource, err := manager.LoadResource("network", network)
			Expect(err).ToNot(HaveOccurred())
			testDB1 := &srv.DbSyncWrapper{DB: testDB}
			tx, err := testDB1.Begin()
			Expect(err).ToNot(HaveOccurred())
			Expect(tx.Create(networkResource)).To(Succeed())
			Expect(tx.Commit()).To(Succeed())
			tx.Close()

			Expect(server.Sync()).To(Succeed())

			sync := gohan_etcd.NewSync(nil)

			writtenConfigRaw, err := sync.Fetch("config/" + networkResource.Path())
			Expect(err).ToNot(HaveOccurred())
			writtenConfig, ok := writtenConfigRaw.(*etcd.Response)
			Expect(ok).To(BeTrue())

			var configContentsRaw interface{}
			Expect(json.Unmarshal([]byte(writtenConfig.Node.Value), &configContentsRaw)).To(Succeed())
			configContents, ok := configContentsRaw.(map[string]interface{})
			Expect(ok).To(BeTrue())
			Expect(configContents).To(HaveKeyWithValue("version", float64(1)))
			var configNetworkRaw interface{}
			Expect(json.Unmarshal([]byte(configContents["body"].(string)), &configNetworkRaw)).To(Succeed())