func compareSchemas(actual, expected []*schema.Schema) {
	g.Expect(actual).To(g.HaveLen(len(expected)))
	for i, s := range actual {
		sortProperties(s)
		sortProperties(expected[i])
		g.Expect(s).To(g.Equal(expected[i]))
	}
}
func waitForNumberOfPodsWithLabel(oc *exutil.CLI, number int, label string) []string {
	g.By(fmt.Sprintf("expecting that there are %d running pods with label name=%s", number, label))

	podNames, err := exutil.WaitForPods(
		oc.KubeClient().Core().Pods(oc.Namespace()),
		exutil.ParseLabelsOrDie("name="+label),
		exutil.CheckPodIsRunningFn,
		number,
		1*time.Minute,
	)
	o.Expect(err).ShouldNot(o.HaveOccurred())
	o.Expect(podNames).Should(o.HaveLen(number))

	return podNames
}
			err := exutil.WaitForADeploymentToComplete(oc.KubeREST().ReplicationControllers(oc.Namespace()), "mongodb")
			if err != nil {
				exutil.DumpDeploymentLogs("mongodb", oc)
			}
			o.Expect(err).ShouldNot(o.HaveOccurred())

			g.By("expecting the mongodb pod is running")
			podNames, err := exutil.WaitForPods(
				oc.KubeREST().Pods(oc.Namespace()),
				exutil.ParseLabelsOrDie("name=mongodb"),
				exutil.CheckPodIsRunningFn,
				1,
				1*time.Minute,
			)
			o.Expect(err).ShouldNot(o.HaveOccurred())
			o.Expect(podNames).Should(o.HaveLen(1))

			g.By("expecting the mongodb service is answering for ping")
			mongo := db.NewMongoDB(podNames[0])
			ok, err := mongo.IsReady(oc)
			o.Expect(err).ShouldNot(o.HaveOccurred())
			o.Expect(ok).Should(o.BeTrue())

			g.By("expecting that we can insert a new record")
			result, err := mongo.Query(oc, `db.foo.save({ "status": "passed" })`)
			o.Expect(err).ShouldNot(o.HaveOccurred())
			o.Expect(result).Should(o.ContainSubstring(`WriteResult({ "nInserted" : 1 })`))

			g.By("expecting that we can read a record")
			findCmd := "printjson(db.foo.find({}, {_id: 0}).toArray())" // don't include _id field to output because it changes every time
			result, err = mongo.Query(oc, findCmd)
Beispiel #4
0
			g.By("starting multiple builds")
			var (
				startedBuilds []string
				counter       int
			)
			bcName := "sample-parallel-build"

			buildWatch, err := oc.Client().Builds(oc.Namespace()).Watch(kapi.ListOptions{
				LabelSelector: buildutil.BuildConfigSelector(bcName),
			})
			defer buildWatch.Stop()

			// Start first build
			stdout, _, err := exutil.StartBuild(oc, bcName, "-o=name")
			o.Expect(err).NotTo(o.HaveOccurred())
			o.Expect(strings.TrimSpace(stdout)).ShouldNot(o.HaveLen(0))
			// extract build name from "build/buildName" resource id
			startedBuilds = append(startedBuilds, strings.TrimSpace(strings.Split(stdout, "/")[1]))

			// Wait for it to become running
			for {
				event := <-buildWatch.ResultChan()
				build := event.Object.(*buildapi.Build)
				o.Expect(buildutil.IsBuildComplete(build)).Should(o.BeFalse())
				if build.Name == startedBuilds[0] && build.Status.Phase == buildapi.BuildPhaseRunning {
					break
				}
			}

			for i := 0; i < 2; i++ {
				stdout, _, err = exutil.StartBuild(oc, bcName, "-o=name")
Beispiel #5
0
func matcherToGomegaMatcher(matcher interface{}) (types.GomegaMatcher, error) {
	switch x := matcher.(type) {
	case string, int, bool, float64:
		return gomega.Equal(x), nil
	case []interface{}:
		var matchers []types.GomegaMatcher
		for _, valueI := range x {
			if subMatcher, ok := valueI.(types.GomegaMatcher); ok {
				matchers = append(matchers, subMatcher)
			} else {
				matchers = append(matchers, gomega.ContainElement(valueI))
			}
		}
		return gomega.And(matchers...), nil
	}
	matcher = sanitizeExpectedValue(matcher)
	if matcher == nil {
		return nil, fmt.Errorf("Missing Required Attribute")
	}
	matcherMap, ok := matcher.(map[string]interface{})
	if !ok {
		panic(fmt.Sprintf("Unexpected matcher type: %T\n\n", matcher))
	}
	var matchType string
	var value interface{}
	for matchType, value = range matcherMap {
		break
	}
	switch matchType {
	case "have-prefix":
		return gomega.HavePrefix(value.(string)), nil
	case "have-suffix":
		return gomega.HaveSuffix(value.(string)), nil
	case "match-regexp":
		return gomega.MatchRegexp(value.(string)), nil
	case "have-len":
		value = sanitizeExpectedValue(value)
		return gomega.HaveLen(value.(int)), nil
	case "contain-element":
		subMatcher, err := matcherToGomegaMatcher(value)
		if err != nil {
			return nil, err
		}
		return gomega.ContainElement(subMatcher), nil
	case "not":
		subMatcher, err := matcherToGomegaMatcher(value)
		if err != nil {
			return nil, err
		}
		return gomega.Not(subMatcher), nil
	case "consist-of":
		subMatchers, err := sliceToGomega(value)
		if err != nil {
			return nil, err
		}
		var interfaceSlice []interface{}
		for _, d := range subMatchers {
			interfaceSlice = append(interfaceSlice, d)
		}
		return gomega.ConsistOf(interfaceSlice...), nil
	case "and":
		subMatchers, err := sliceToGomega(value)
		if err != nil {
			return nil, err
		}
		return gomega.And(subMatchers...), nil
	case "or":
		subMatchers, err := sliceToGomega(value)
		if err != nil {
			return nil, err
		}
		return gomega.Or(subMatchers...), nil
	case "gt", "ge", "lt", "le":
		// Golang json escapes '>', '<' symbols, so we use 'gt', 'le' instead
		comparator := map[string]string{
			"gt": ">",
			"ge": ">=",
			"lt": "<",
			"le": "<=",
		}[matchType]
		return gomega.BeNumerically(comparator, value), nil

	default:
		return nil, fmt.Errorf("Unknown matcher: %s", matchType)

	}
}
	g.Describe("oc start-build source-build --wait", func() {
		g.It("Source: should start a build and wait for the build failed and build pod being killed by kubelet", func() {

			g.By("calling oc create source-build")
			err := oc.Run("create").Args("-f", sourceFixture).Execute()
			o.Expect(err).NotTo(o.HaveOccurred())

			g.By("starting the build with --wait flag")
			_, err = oc.Run("start-build").Args("source-build", "--wait").Output()
			o.Expect(err).To(o.HaveOccurred())

			g.By("verifying the build status")
			builds, err := oc.REST().Builds(oc.Namespace()).List(kapi.ListOptions{})
			o.Expect(err).NotTo(o.HaveOccurred())
			o.Expect(builds.Items).To(o.HaveLen(1))

			build := builds.Items[0]
			o.Expect(build.Status.Phase).Should(o.BeEquivalentTo(buildapi.BuildPhaseFailed))

			g.By("verifying the build pod status")
			pod, err := oc.KubeREST().Pods(oc.Namespace()).Get(buildutil.GetBuildPodName(&build))
			o.Expect(err).NotTo(o.HaveOccurred())
			o.Expect(pod.Status.Phase).Should(o.BeEquivalentTo(kapi.PodFailed))
			o.Expect(pod.Status.Reason).Should(o.ContainSubstring("DeadlineExceeded"))
		})
	})

	g.Describe("oc start-build docker-build --wait", func() {
		g.It("Docker: should start a build and wait for the build failed and build pod being killed by kubelet", func() {
Beispiel #7
0
	g.It("should respect image stream tag reference policy [Conformance]", func() {
		o.Expect(oc.Run("create").Args("-f", resolutionFixture).Execute()).NotTo(o.HaveOccurred())

		name := "deployment-image-resolution"
		o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentImageTriggersResolved(2))).NotTo(o.HaveOccurred())

		is, err := oc.Client().ImageStreams(oc.Namespace()).Get(name)
		o.Expect(err).NotTo(o.HaveOccurred())
		o.Expect(is.Status.DockerImageRepository).NotTo(o.BeEmpty())
		o.Expect(is.Status.Tags["direct"].Items).NotTo(o.BeEmpty())
		o.Expect(is.Status.Tags["pullthrough"].Items).NotTo(o.BeEmpty())

		dc, err := oc.Client().DeploymentConfigs(oc.Namespace()).Get(name)
		o.Expect(err).NotTo(o.HaveOccurred())
		o.Expect(dc.Spec.Triggers).To(o.HaveLen(3))

		imageID := is.Status.Tags["pullthrough"].Items[0].Image
		resolvedReference := fmt.Sprintf("%s@%s", is.Status.DockerImageRepository, imageID)
		directReference := is.Status.Tags["direct"].Items[0].DockerImageReference

		// controller should be using pullthrough for this (pointing to local registry)
		o.Expect(dc.Spec.Triggers[1].ImageChangeParams).NotTo(o.BeNil())
		o.Expect(dc.Spec.Triggers[1].ImageChangeParams.LastTriggeredImage).To(o.Equal(resolvedReference))
		o.Expect(dc.Spec.Template.Spec.Containers[0].Image).To(o.Equal(resolvedReference))

		// controller should have preferred the base image
		o.Expect(dc.Spec.Triggers[2].ImageChangeParams).NotTo(o.BeNil())
		o.Expect(dc.Spec.Triggers[2].ImageChangeParams.LastTriggeredImage).To(o.Equal(directReference))
		o.Expect(dc.Spec.Template.Spec.Containers[1].Image).To(o.Equal(directReference))
	})
Beispiel #8
0
		g.Expect(subject.crc64()).To(g.Equal(uint64(3048486384098978521)))
	})

	It("should perform", func() {
		g.Expect(subject.perform(mockFact{FactKey(33): []int64{1}}, NewState())).To(g.BeTrue())
		g.Expect(subject.perform(mockFact{FactKey(33): []int64{4}}, NewState())).To(g.BeFalse())
		g.Expect(subject.perform(mockFact{FactKey(34): []int64{1}}, NewState())).To(g.BeFalse())
	})

	It("should capture state", func() {
		state := NewState()
		g.Expect(subject.perform(mockFact{FactKey(33): []int64{1}}, state)).To(g.BeTrue())
		g.Expect(state.rules).To(g.Equal(map[uint64]bool{
			3048486384098978521: true,
		}))
		g.Expect(state.facts).To(g.HaveLen(1))
		g.Expect(state.facts).To(g.HaveKey(FactKey(33)))
	})
})

var _ = Describe("conjunction", func() {
	var subject Rule

	BeforeEach(func() {
		subject = All(
			CheckFact(33, OneOf([]int64{3, 2, 1})),
			CheckFact(33, OneOf([]int64{4, 5, 6})),
		)
	})

	It("should return a string", func() {
Beispiel #9
0
		in:   `{"match-regexp": "foo"}`,
		want: gomega.MatchRegexp("foo"),
	},

	// Collection
	{
		in:   `{"consist-of": ["foo"]}`,
		want: gomega.ConsistOf(gomega.Equal("foo")),
	},
	{
		in:   `{"contain-element": "foo"}`,
		want: gomega.ContainElement(gomega.Equal("foo")),
	},
	{
		in:   `{"have-len": 3}`,
		want: gomega.HaveLen(3),
	},

	// Negation
	{
		in:   `{"not": "foo"}`,
		want: gomega.Not(gomega.Equal("foo")),
	},
	// Complex logic
	{
		in:              `{"and": ["foo", "foo"]}`,
		want:            gomega.And(gomega.Equal("foo"), gomega.Equal("foo")),
		useNegateTester: true,
	},
	{
		in:              `{"and": [{"have-prefix": "foo"}, "foo"]}`,
Beispiel #10
0
		), 91)

		subject.Resolve(All(
			mockFactCountry.MustNotBe(EqualTo(dict.Add("CA"))),
			mockFactDomains.MustInclude(OneOf(dict.AddSlice("b.com", "c.com"))),
			mockFactDomains.MustInclude(OneOf(dict.AddSlice("d.com", "a.com"))),
		), 92)

		subject.Resolve(All(
			mockFactCountry.MustBe(OneOf(dict.AddSlice("US"))),
			mockFactBrowser.MustBe(NoneOf(dict.AddSlice("OP"))),
		), 93)
	})

	It("should register targets", func() {
		g.Expect(subject.registry).To(g.HaveLen(3))
	})

	DescribeTable("matching",
		func(fact *mockFactStruct, expected []int64) {
			fact.D = dict // assign dict
			g.Expect(subject.Select(fact)).To(g.ConsistOf(expected))
		},

		Entry("blank",
			&mockFactStruct{}, []int64{}),
		Entry("91 & 92 have domain inclusions, 93 matches",
			&mockFactStruct{Country: "US"}, []int64{93}),
		Entry("91 & 93 match, 92 has only one matching domain rule",
			&mockFactStruct{Country: "US", Domains: []string{"a.com", "d.com"}}, []int64{91, 93}),
		Entry("92 & 93 match, 91 excludes c.com",