Esempio n. 1
0
func TestExtractFormFromReader(t *testing.T) {
	form, err := sweet.FromReader(strings.NewReader(page)).SelectForm("#first-form")

	if err != nil {
		t.Errorf("Expected nil, got", err)
	}

	expectedFormAction := "/form1"
	expectedFormMethod := "POST"
	expectedFormBody := url.Values{}
	expectedFormBody.Add("auth_token", "super_secret")
	expectedFormBody.Add("user", "diego")

	if form.Action != expectedFormAction {
		t.Errorf("Expected %v, got %v", expectedFormAction, form.Action)
	}

	if form.Method != expectedFormMethod {
		t.Errorf("Expected %v, got %v", expectedFormMethod, form.Method)
	}

	if !reflect.DeepEqual(form.Fields, expectedFormBody) {
		t.Errorf("Expected %v, got %v", expectedFormBody, form.Fields)
	}
}
Esempio n. 2
0
func TestExtractFormErrEmptyForm(t *testing.T) {
	form, err := sweet.FromReader(strings.NewReader(page)).SelectForm("#second-form")

	expectedErr := sweet.ErrEmptyForm{"#second-form"}

	if err.Error() != expectedErr.Error() {
		t.Errorf("Expected %v, got %v", expectedErr, err.Error())
	}

	if form != nil {
		t.Errorf("Expected %v, got %v", nil, form)
	}
}
Esempio n. 3
0
func TestExtractFormErrNotFound(t *testing.T) {
	form, err := sweet.FromReader(strings.NewReader(page)).SelectForm("#not-existent")

	expectedErr := sweet.ErrNotFound{"#not-existent"}

	if err.Error() != expectedErr.Error() {
		t.Errorf("Expected %v, got %v", expectedErr, err.Error())
	}

	if form != nil {
		t.Errorf("Expected %v, got %v", nil, form)
	}
}