Esempio n. 1
0
File: rest.go Progetto: nkuacac/pat
func (r *rest) Login(ctx context.Context) error {
	body := &LoginResponse{}

	iterationIndex, exist := ctx.GetInt("iterationIndex")
	if !exist {
		return errors.New("Iteration Index does not exist in context map")
	}

	var userList, passList string
	if _, ok := ctx.GetString("rest:username"); ok {
		userList, _ = ctx.GetString("rest:username")
	} else {
		return errors.New("argument rest:username does not exist")
	}
	if _, ok := ctx.GetString("rest:password"); ok {
		passList, _ = ctx.GetString("rest:password")
	} else {
		return errors.New("argument rest:password does not exist")
	}

	return checkTargetted(ctx, func(loginEndpoint string, apiEndpoint string) error {
		return r.PostToUaaSuccessfully(fmt.Sprintf("%s/oauth/token", loginEndpoint), r.oauthInputs(credentialsForWorker(iterationIndex, userList, passList)), body, func(reply Reply) error {
			ctx.PutString("token", body.Token)
			return r.targetSpace(ctx)
		})
	})
}
Esempio n. 2
0
File: cf.go Progetto: nkuacac/pat
func Delete(ctx context.Context) error {
	appNames, _ := ctx.GetString("appNames")
	if appNames == "" {
		return errors.New("No app to delete")
	}
	appNamesArray := strings.Split(appNames, ",")
	appNameToDelete := appNamesArray[len(appNamesArray)-1]

	appNames = strings.Replace(appNames, ","+appNameToDelete, "", -1)
	appNames = strings.Replace(appNames, appNameToDelete, "", -1)
	ctx.PutString("appNames", appNames)
	return expectCfToSay("Deleting app", "delete", appNameToDelete, "-f")
}
Esempio n. 3
0
File: rest.go Progetto: nkuacac/pat
func (r *rest) Target(ctx context.Context) error {
	var target string
	if _, ok := ctx.GetString("rest:target"); ok {
		target, _ = ctx.GetString("rest:target")
	} else {
		return errors.New("argument rest:target does not exist")
	}

	body := &TargetResponse{}
	return r.GetSuccessfully("", target+"/v2/info", nil, body, func(reply Reply) error {
		ctx.PutString("loginEndpoint", body.LoginEndpoint)
		ctx.PutString("apiEndpoint", target)
		return nil
	})
}
Esempio n. 4
0
func PopulateAppContext(appPath string, manifestPath string, ctx context.Context) error {
	normalizedAppPath, err := normalizePath(appPath)
	if err != nil {
		return err
	}
	ctx.PutString("app", normalizedAppPath)

	normalizedManifestPath, err := normalizePath(manifestPath)
	if err != nil {
		return err
	}
	ctx.PutString("app:manifest", normalizedManifestPath)

	return nil
}
Esempio n. 5
0
File: cf.go Progetto: nkuacac/pat
func Dummy(ctx context.Context) error {
	guid, _ := uuid.NewV4()
	appName := "pats-" + guid.String()
	appNames, _ := ctx.GetString("appNames")

	if appNames != "" {
		appNames += fmt.Sprintf(",%s", appName)
	} else {
		appNames = appName
	}
	ctx.PutString("appNames", appNames)

	time.Sleep(time.Duration(random(1, 5)) * time.Second)
	return nil
}
Esempio n. 6
0
File: rest.go Progetto: nkuacac/pat
func (r *rest) targetSpace(ctx context.Context) error {
	apiEndpoint, _ := ctx.GetString("apiEndpoint")

	var space string
	if _, ok := ctx.GetString("rest:space"); ok {
		space, _ = ctx.GetString("rest:space")
	} else {
		return errors.New("argument rest:space does not exist")
	}
	replyBody := &SpaceResponse{}

	return checkLoggedIn(ctx, func(token string) error {
		return r.GetSuccessfully(token, fmt.Sprintf("%s/v2/spaces?q=name:%s", apiEndpoint, space), nil, replyBody, func(reply Reply) error {
			return checkSpaceExists(replyBody, func() error {
				ctx.PutString("space_guid", replyBody.Resources[0].Metadata.Guid)
				return nil
			})
		})
	})
}
Esempio n. 7
0
File: cf.go Progetto: nkuacac/pat
func Push(ctx context.Context) error {
	guid, _ := uuid.NewV4()
	pathToApp, _ := ctx.GetString("app")
	pathToManifest, _ := ctx.GetString("app:manifest")
	appName := "pats-" + guid.String()
	appNames, _ := ctx.GetString("appNames")

	if appNames != "" {
		appNames += fmt.Sprintf(",%s", appName)
	} else {
		appNames = appName
	}
	ctx.PutString("appNames", appNames)

	if pathToManifest == "" {
		return expectCfToSay("App started", "push", appName, "-m", "64M", "-p", pathToApp)
	} else {
		return expectCfToSay("App started", "push", appName, "-p", pathToApp, "-f", pathToManifest)
	}
}
Esempio n. 8
0
	. "github.com/onsi/gomega"
)

var _ = Describe("Context map", func() {

	var (
		localContext context.Context
	)

	JustBeforeEach(func() {
		localContext = context.New()
	})

	Context("String values in context map", func() {
		It("uses a key to identify store fields", func() {
			localContext.PutString("key1", "abc")
			localContext.PutString("key2", "123")

			result, exists := localContext.GetString("key1")
			Ω(result).Should(Equal("abc"))
			Ω(exists).Should(Equal(true))

			result, exists = localContext.GetString("key2")
			Ω(result).Should(Equal("123"))
			Ω(exists).Should(Equal(true))
		})

		It("can store string value as provided", func() {
			localContext.PutString("str", "This is a long string \n")

			result, _ := localContext.GetString("str")
Esempio n. 9
0
File: rest.go Progetto: nkuacac/pat
func PopulateRestContext(target string, username string, password string, space string, ctx context.Context) {
	ctx.PutString("rest:target", target)
	ctx.PutString("rest:username", username)
	ctx.PutString("rest:password", password)
	ctx.PutString("rest:space", space)
}
Esempio n. 10
0
					Ω(result.Steps).Should(HaveLen(2))
					Ω(result.Steps[0].Duration.Seconds()).Should(BeNumerically("~", 1, 0.1))
					Ω(result.Steps[1].Duration.Seconds()).Should(BeNumerically("~", 2, 0.1))
				})
			})

			Describe("Workload context map sending over Redis", func() {

				AfterEach(func() {
					workloadCtx = context.New()
				})

				Describe("Contents in the context map", func() {
					It("should send all the keys in the context over redis", func() {
						worker := NewRedisWorker(conn)
						workloadCtx.PutString("cfUsername", "user1")
						workloadCtx.PutString("RandomKey", "some info")
						_ = worker.Time("recordWorkerInfo", workloadCtx)
						Ω(wasCalledWithWorkerUsername).Should(Equal("user1"))
						Ω(wasCalledWithRandomKey).Should(Equal("some info"))
					})

					It("should retain 'int' type content when sending over redis", func() {
						worker := NewRedisWorker(conn)
						workloadCtx.PutInt("iterationIndex", 100)
						_ = worker.Time("recordWorkerIndex", workloadCtx)
						Ω(wasCalledWithWorkerIndex).Should(Equal(100))
					})

					It("should retain 'bool' type content when sending over redis", func() {
						worker := NewRedisWorker(conn)