Example #1
0
func testWriteAndAttachRandomContainers(t *testing.T, num int, dir string, parent entity.Entity) {
	for i := 0; i < num; i++ {
		name := randomString(8)

		kubeContainer := kube.Container{
			Name:                   name,
			Image:                  randomString(6),
			ImagePullPolicy:        kube.PullAlways,
			TerminationMessagePath: kube.TerminationMessagePathDefault,
		}
		filename := path.Join(dir, name+ContainerExtension)

		container, err := entity.NewContainer(kubeContainer, kube.ObjectMeta{}, filename)
		assert.NoError(t, err)

		testWriteYAMLToFile(t, filename, &kubeContainer)

		assert.NoError(t, parent.Attach(container), "should be able to attach container to pod")
	}
}
Example #2
0
func testCompareEntity(t *testing.T, expected, actual entity.Entity) bool {
	assert.Equal(t, expected.Source(), actual.Source(), "sources should match")
	assert.Equal(t, expected.DefaultMeta(), actual.DefaultMeta())

	actualImages := actual.Images()
	expectedImages := expected.Images()
	assert.Len(t, actualImages, len(expectedImages))
	for _, expectImage := range expectedImages {
		found := false
		for _, actualImage := range actualImages {
			found = expectImage.Equal(actualImage)
			if found {
				break
			}
		}
		assert.True(t, found, "should have found image")
	}

	expectedDeploy, err := expected.Deployment()
	assert.NoError(t, err)
	actualDeploy, err := actual.Deployment()
	assert.NoError(t, err)

	if !assert.True(t, expectedDeploy.Equal(actualDeploy)) {
		t.Log(expectedDeploy.Diff(actualDeploy))
		return false
	}
	return true
}