Beispiel #1
0
func runWithContext(s *gocql.Session, ctx *cqlc.Context) string {

	result := "FAILED"

	shared := Shared{
		Id:    "foo",
		Value: "bar",
	}

	err := ctx.Store(SHARED.Bind(shared)).Exec(s)

	if err != nil {
		log.Fatalf("Could not store data: %v", err)
		os.Exit(1)
	}

	found, value := get(s, ctx, "foo")

	if found && value == "bar" {

		err := ctx.Upsert(SHARED).SetString(SHARED.VALUE, "baz").Where(SHARED.ID.Eq("foo")).Exec(s)
		if err != nil {
			log.Fatalf("Could not upsert row: %v", err)
			os.Exit(1)
		}

		found, value := get(s, ctx, "foo")

		if found && value == "baz" {

			err = ctx.Delete().From(SHARED).Where(SHARED.ID.Eq("foo")).Exec(s)
			if err != nil {
				log.Fatalf("Could not delete row: %v", err)
				os.Exit(1)
			}

			found, _ := get(s, ctx, "foo")

			if !found {
				result = "PASSED"
			}
		}

	}

	return result
}