Beispiel #1
0
func createWorkspace() (*models.Workspace, error) {
	ws := &models.Workspace{
		ObjectId:     bson.NewObjectId(),
		OriginId:     bson.NewObjectId(),
		Name:         "My Workspace",
		Slug:         "my-workspace",
		ChannelId:    strconv.FormatInt(rand.Int63(), 10),
		MachineUID:   bson.NewObjectId().Hex(),
		MachineLabel: "koding-vm-0",
		Owner:        "cihangir",
		RootPath:     "/home/cihangir",
		IsDefault:    true,
	}

	return ws, modelhelper.CreateWorkspace(ws)
}
Beispiel #2
0
func TestCollaborationOperationsEndPrivateMessage(t *testing.T) {
	r := runner.New("collaboration-EndPrivateMessage-tests")
	err := r.Init()
	if err != nil {
		panic(err)
	}

	defer r.Close()

	appConfig := config.MustRead(r.Conf.Path)
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	// init with defaults
	mongoCache := cache.NewMongoCacheWithTTL(modelhelper.Mongo.Session)
	defer mongoCache.StopGC()

	handler := New(r.Log, mongoCache, appConfig, r.Kite)

	Convey("while testing EndPrivateMessage", t, func() {
		req := &models.Ping{
			AccountId: 1,
			FileId:    fmt.Sprintf("%d", rand.Int63()),
		}
		Convey("should be able to create the channel first", func() {
			creator := socialapimodels.CreateAccountWithTest() // init account
			c := socialapimodels.NewChannel()                  // init channel
			c.CreatorId = creator.Id                           // set Creator id
			c.TypeConstant = socialapimodels.Channel_TYPE_COLLABORATION
			So(c.Create(), ShouldBeNil)
			cp, err := c.AddParticipant(creator.Id)
			So(err, ShouldBeNil)
			So(cp, ShouldNotBeNil)

			req.AccountId = c.CreatorId // set real account id
			req.ChannelId = c.Id        // set real channel id

			ws := &mongomodels.Workspace{
				ObjectId:     bson.NewObjectId(),
				OriginId:     bson.NewObjectId(),
				Name:         "My Workspace",
				Slug:         "my-workspace",
				ChannelId:    strconv.FormatInt(req.ChannelId, 10),
				MachineUID:   bson.NewObjectId().Hex(),
				MachineLabel: "koding-vm-0",
				Owner:        "cihangir",
				RootPath:     "/home/cihangir",
				IsDefault:    true,
			}

			So(modelhelper.CreateWorkspace(ws), ShouldBeNil)

			Convey("should be able to delete channel", func() {
				err = handler.EndPrivateMessage(req)
				So(err, ShouldBeNil)
				Convey("deleted channel should not be exist", func() {
					channel := socialapimodels.NewChannel()
					err := channel.ById(req.ChannelId)
					So(err, ShouldEqual, bongo.RecordNotFound)
				})
				Convey("channel id in workspace should not be exist", func() {
					ws2, err := modelhelper.GetWorkspaceByChannelId(
						strconv.FormatInt(req.ChannelId, 10),
					)
					So(err, ShouldEqual, mgo.ErrNotFound)
					So(ws2, ShouldEqual, nil)
				})
			})

			Convey("if not a participant, should not be able to delete channel", func() {
				req.AccountId = 1
				err = handler.EndPrivateMessage(req)
				So(err, ShouldBeNil)
				Convey("channel should exist", func() {
					channel := socialapimodels.NewChannel()
					err := channel.ById(req.ChannelId)
					So(err, ShouldBeNil)
				})
			})

			Convey("if channel doesnt exists, should success", func() {
				req.ChannelId = 1
				err = handler.EndPrivateMessage(req)
				So(err, ShouldBeNil)
				Convey("channel should not exist", func() {
					channel := socialapimodels.NewChannel()
					err := channel.ById(req.ChannelId)
					So(err, ShouldEqual, bongo.RecordNotFound)
				})
			})
		})
	})
}
Beispiel #3
0
func prepareSingleWorkspace(creator, participant1, participant2 *socialapimodels.Account) (
	*mongomodels.Machine, // m1
	*mongomodels.Workspace, // m1 ws1
) {

	ownerUser, err := modelhelper.GetUserByAccountId(creator.OldId)
	So(err, ShouldBeNil)

	participant1User, err := modelhelper.GetUserByAccountId(participant1.OldId)
	So(err, ShouldBeNil)

	participant2User, err := modelhelper.GetUserByAccountId(participant2.OldId)
	So(err, ShouldBeNil)

	// sample  machine struct
	m1 := &mongomodels.Machine{
		ObjectId: bson.NewObjectId(),
		Uid:      bson.NewObjectId().Hex(),
		Users: []mongomodels.MachineUser{
			{ // real owner
				Id:    ownerUser.ObjectId,
				Sudo:  true,
				Owner: true,
			},
			{ // secondary owner
				Id:        participant1User.ObjectId,
				Sudo:      false,
				Owner:     true,
				Permanent: false,
			},
			{ // random
				Id:        participant2User.ObjectId,
				Sudo:      false,
				Owner:     true,
				Permanent: false,
			},
		},
		CreatedAt: time.Now().UTC(),
		Status: mongomodels.MachineStatus{
			State:      "running",
			ModifiedAt: time.Now().UTC(),
		},
		Assignee:    mongomodels.MachineAssignee{},
		UserDeleted: false,
	}

	So(modelhelper.CreateMachine(m1), ShouldBeNil)

	//
	// create the first channel
	//
	c1 := socialapimodels.NewChannel() // init channel
	c1.CreatorId = creator.Id          // set Creator id
	c1.TypeConstant = socialapimodels.Channel_TYPE_COLLABORATION
	So(c1.Create(), ShouldBeNil)

	c1p1, err := c1.AddParticipant(creator.Id)
	So(err, ShouldBeNil)
	So(c1p1, ShouldNotBeNil)

	c1p2, err := c1.AddParticipant(participant1.Id)
	So(err, ShouldBeNil)
	So(c1p2, ShouldNotBeNil)

	c1p3, err := c1.AddParticipant(participant2.Id)
	So(err, ShouldBeNil)
	So(c1p3, ShouldNotBeNil)

	m1ws1 := &mongomodels.Workspace{
		ObjectId:     bson.NewObjectId(),
		OriginId:     bson.ObjectIdHex(creator.OldId),
		Name:         "My Workspace",
		Slug:         "m1ws1",
		ChannelId:    strconv.FormatInt(c1.Id, 10),
		MachineUID:   m1.Uid,
		MachineLabel: "koding-vm-0",
		Owner:        "cihangir",
		RootPath:     "/home/cihangir",
		IsDefault:    true,
	}

	So(modelhelper.CreateWorkspace(m1ws1), ShouldBeNil)

	return m1, m1ws1
}