Example #1
0
func createMachine(t *testing.T) *models.Machine {
	m := &models.Machine{
		ObjectId:    bson.NewObjectId(),
		Uid:         bson.NewObjectId().Hex(),
		QueryString: (&protocol.Kite{ID: uuid.NewV4().String()}).String(),
		IpAddress:   utils.RandomString(),
		RegisterURL: (&url.URL{
			Scheme: "http",
			Host:   utils.RandomString() + ":56789",
			Path:   "/kite",
		}).String(),
		Provider: "koding",
		Users: []models.MachineUser{
			// real owner
			{
				Id:       bson.NewObjectId(),
				Sudo:     true,
				Owner:    true,
				Username: "******",
			},
			// secondary owner
			{
				Id:    bson.NewObjectId(),
				Sudo:  false,
				Owner: true,
			},
			// has sudo but not owner
			{
				Id:    bson.NewObjectId(),
				Sudo:  true,
				Owner: false,
			},
			// random user
			{
				Id:    bson.NewObjectId(),
				Sudo:  false,
				Owner: false,
			},
		},
		CreatedAt: time.Now().UTC(),
		Status: models.MachineStatus{
			State:      "running",
			ModifiedAt: time.Now().UTC(),
		},
		Assignee:    models.MachineAssignee{},
		UserDeleted: false,
	}

	err := modelhelper.CreateMachine(m)
	if err != nil {
		t.Errorf("createMachine()=%s", err)
	}

	return m
}
Example #2
0
func modifyURL(u *URL) {
	if u.IsNil() {
		return
	}

	u.URL.Host = utils.RandomString()

	if u.URL.User != nil {
		u.URL.User = url.UserPassword(utils.RandomString(), "")
	}
}