Ejemplo n.º 1
0
func TestCheckinListParamsExpansion(t *testing.T) {
	testCases := []struct {
		InitialBody  url.Values
		Expand       []string
		ExpectedBody url.Values
	}{
		{
			InitialBody:  url.Values{"foo": {"bar"}},
			Expand:       []string{},
			ExpectedBody: url.Values{"foo": {"bar"}},
		},
		{
			InitialBody:  url.Values{"foo": {"bar", "baz"}},
			Expand:       []string{"data", "data.foo"},
			ExpectedBody: url.Values{"foo": {"bar", "baz"}, "expand[]": {"data", "data.foo"}},
		},
	}

	for _, testCase := range testCases {
		p := stripe.ListParams{}

		for _, exp := range testCase.Expand {
			p.Expand(exp)
		}

		body := testCase.InitialBody
		p.AppendTo(&body)

		if !reflect.DeepEqual(body, testCase.ExpectedBody) {
			t.Fatalf("Expected body of %v but got %v.", testCase.ExpectedBody, body)
		}
	}
}
Ejemplo n.º 2
0
func TestCheckinListParamsExpansion(t *testing.T) {
	testCases := []struct {
		InitialBody  [][2]string
		Expand       []string
		ExpectedBody [][2]string
	}{
		{
			InitialBody:  [][2]string{{"foo", "bar"}},
			Expand:       []string{},
			ExpectedBody: [][2]string{{"foo", "bar"}},
		},
		{
			InitialBody:  [][2]string{{"foo", "bar"}, {"foo", "baz"}},
			Expand:       []string{"data", "data.foo"},
			ExpectedBody: [][2]string{{"foo", "bar"}, {"foo", "baz"}, {"expand[]", "data"}, {"expand[]", "data.foo"}},
		},
	}

	for _, testCase := range testCases {
		p := stripe.ListParams{}

		for _, exp := range testCase.Expand {
			p.Expand(exp)
		}

		body := valuesFromArray(testCase.InitialBody)
		p.AppendTo(body)

		expected := valuesFromArray(testCase.ExpectedBody)
		if !reflect.DeepEqual(body, expected) {
			t.Fatalf("Expected body of %v but got %v.", expected, body)
		}
	}
}