示例#1
0
文件: input.go 项目: redspread/spread
func (d *FileInput) base() (entity.Entity, error) {
	objects, err := d.Objects()
	if err != nil {
		return nil, err
	}

	// create app
	return entity.NewApp(nil, kube.ObjectMeta{}, string(d.FileSource), objects...)
}
示例#2
0
func TestInputRCAndPod(t *testing.T) {
	input := testTempFileInput(t)
	defer os.RemoveAll(input.Path())

	// setup pod
	kubePod := testKubePod()

	podFile := fmt.Sprintf("test.%s.%s", PodExtension, testRandomExtension())
	podPath := path.Join(input.Path(), podFile)
	testWriteYAMLToFile(t, podPath, kubePod)
	testClearTypeInfo(kubePod)
	pod, err := entity.NewPod(kubePod, kube.ObjectMeta{}, podPath)
	assert.NoError(t, err)

	// setup rc
	objects := testWriteRandomObjects(t, input.Path(), 5)
	kubeRC := &kube.ReplicationController{
		ObjectMeta: kube.ObjectMeta{
			Name:      "spread",
			Namespace: kube.NamespaceDefault,
		},
		TypeMeta: unversioned.TypeMeta{
			Kind:       "ReplicationController",
			APIVersion: "v1",
		},
		Spec: kube.ReplicationControllerSpec{
			Selector: map[string]string{"valid": "selector"},
			Template: &kube.PodTemplateSpec{
				Spec: kubePod.Spec,
			},
		},
	}

	rcFile := fmt.Sprintf("test.%s.%s", RCExtension, testRandomExtension())
	rcPath := path.Join(input.Path(), rcFile)
	testWriteYAMLToFile(t, rcPath, kubeRC)
	testClearTypeInfo(kubeRC)
	rc, err := entity.NewReplicationController(kubeRC, kube.ObjectMeta{}, rcPath)
	assert.NoError(t, err)

	expected, err := entity.NewApp(nil, kube.ObjectMeta{}, input.Path(), objects...)
	assert.NoError(t, err)

	// attach rc and pod
	err = expected.Attach(rc)
	assert.NoError(t, err)
	err = expected.Attach(pod)
	assert.NoError(t, err)

	// generate entity
	actual, err := input.Build()
	assert.NoError(t, err, "should have built entity successfully")

	testCompareEntity(t, expected, actual)
}
示例#3
0
func TestInputPod(t *testing.T) {
	input := testTempFileInput(t)
	defer os.RemoveAll(input.Path())

	kubePod := testKubePod()

	podFile := fmt.Sprintf("test.%s.%s", PodExtension, testRandomExtension())
	podPath := path.Join(input.Path(), podFile)
	testWriteYAMLToFile(t, podPath, kubePod)

	testClearTypeInfo(kubePod)

	objects := testWriteRandomObjects(t, input.Path(), 5)

	expectedPod, err := entity.NewPod(kubePod, kube.ObjectMeta{}, podPath)
	assert.NoError(t, err)
	expected, err := entity.NewApp([]entity.Entity{expectedPod}, kube.ObjectMeta{}, input.Path(), objects...)
	assert.NoError(t, err)

	actual, err := input.Build()
	assert.NoError(t, err, "should have built entity successfully")

	testCompareEntity(t, expected, actual)
}