Beispiel #1
0
func TestUnmarshalHooksWithInvalidData(t *testing.T) {
	hook := configs.Hooks{}
	err := hook.UnmarshalJSON([]byte(`{invalid-json}`))
	if err == nil {
		t.Error("Expected error to occur but it was nil")
	}
}
Beispiel #2
0
func TestMarshalUnmarshalHooks(t *testing.T) {
	timeout := time.Second

	prestart := configs.NewCommandHook(configs.Command{
		Path:    "/var/vcap/hooks/prestart",
		Args:    []string{"--pid=123"},
		Env:     []string{"FOO=BAR"},
		Dir:     "/var/vcap",
		Timeout: &timeout,
	})

	hook := configs.Hooks{
		Prestart: []configs.Hook{prestart},
	}
	hooks, err := hook.MarshalJSON()
	if err != nil {
		t.Fatal(err)
	}

	umMhook := configs.Hooks{}
	err = umMhook.UnmarshalJSON(hooks)
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(umMhook.Prestart[0], prestart) {
		t.Errorf("Expected hooks to be equal after mashaling -> unmarshaling them: %+v, %+v", umMhook.Prestart[0], prestart)
	}
}
Beispiel #3
0
func TestUnmarshalHooks(t *testing.T) {
	timeout := time.Second

	prestartCmd := configs.NewCommandHook(configs.Command{
		Path:    "/var/vcap/hooks/prestart",
		Args:    []string{"--pid=123"},
		Env:     []string{"FOO=BAR"},
		Dir:     "/var/vcap",
		Timeout: &timeout,
	})
	prestart, err := json.Marshal(prestartCmd.Command)
	if err != nil {
		t.Fatal(err)
	}

	hook := configs.Hooks{}
	err = hook.UnmarshalJSON([]byte(fmt.Sprintf(`{"Prestart" :[%s]}`, prestart)))
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(hook.Prestart[0], prestartCmd) {
		t.Errorf("Expected prestart to equal %+v but it was %+v",
			prestartCmd, hook.Prestart[0])
	}
}