MCPcopy
hub / github.com/redspread/spread / TestInputRCAndPod

Function TestInputRCAndPod

pkg/input/dir/input_test.go:42–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestInputRCAndPod(t *testing.T) {
43 input := testTempFileInput(t)
44 defer os.RemoveAll(input.Path())
45
46 // setup pod
47 kubePod := testKubePod()
48
49 podFile := fmt.Sprintf("test.%s.%s", PodExtension, testRandomExtension())
50 podPath := path.Join(input.Path(), podFile)
51 testWriteYAMLToFile(t, podPath, kubePod)
52 testClearTypeInfo(kubePod)
53 pod, err := entity.NewPod(kubePod, kube.ObjectMeta{}, podPath)
54 assert.NoError(t, err)
55
56 // setup rc
57 objects := testWriteRandomObjects(t, input.Path(), 5)
58 kubeRC := &kube.ReplicationController{
59 ObjectMeta: kube.ObjectMeta{
60 Name: "spread",
61 Namespace: kube.NamespaceDefault,
62 },
63 TypeMeta: unversioned.TypeMeta{
64 Kind: "ReplicationController",
65 APIVersion: "v1",
66 },
67 Spec: kube.ReplicationControllerSpec{
68 Selector: map[string]string{"valid": "selector"},
69 Template: &kube.PodTemplateSpec{
70 Spec: kubePod.Spec,
71 },
72 },
73 }
74
75 rcFile := fmt.Sprintf("test.%s.%s", RCExtension, testRandomExtension())
76 rcPath := path.Join(input.Path(), rcFile)
77 testWriteYAMLToFile(t, rcPath, kubeRC)
78 testClearTypeInfo(kubeRC)
79 rc, err := entity.NewReplicationController(kubeRC, kube.ObjectMeta{}, rcPath)
80 assert.NoError(t, err)
81
82 expected, err := entity.NewApp(nil, kube.ObjectMeta{}, input.Path(), objects...)
83 assert.NoError(t, err)
84
85 // attach rc and pod
86 err = expected.Attach(rc)
87 assert.NoError(t, err)
88 err = expected.Attach(pod)
89 assert.NoError(t, err)
90
91 // generate entity
92 actual, err := input.Build()
93 assert.NoError(t, err, "should have built entity successfully")
94
95 testCompareEntity(t, expected, actual)
96}
97
98func testTempFileInput(t *testing.T) *FileInput {
99 dir := testTempDir(t)

Callers

nothing calls this directly

Calls 10

AttachMethod · 0.95
testTempFileInputFunction · 0.85
testKubePodFunction · 0.85
testRandomExtensionFunction · 0.85
testWriteYAMLToFileFunction · 0.85
testClearTypeInfoFunction · 0.85
testWriteRandomObjectsFunction · 0.85
testCompareEntityFunction · 0.85
PathMethod · 0.80
BuildMethod · 0.65

Tested by

no test coverage detected