Esempio n. 1
0
func TestJSONArrayInt64_Scan_nil(t *testing.T) {
	var got pqt.JSONArrayInt64

	if err := got.Scan(nil); err != nil {
		t.Fatalf("unexpected error: %s", err.Error())
	}
	if got != nil {
		t.Errorf("unexpected output, expected: %T\n	%v\n	but got: %T\n	%v,", nil, nil, got, got)

	}
}
Esempio n. 2
0
func TestJSONArrayInt64_Scan(t *testing.T) {
	success := map[string]pqt.JSONArrayInt64{
		"[1,2,3,4]": {0: 1, 1: 2, 2: 3, 3: 4},
		"[]":        {},
	}

SuccessLoop:
	for src, expected := range success {
		var got pqt.JSONArrayInt64

		err := got.Scan(src)
		if err != nil {
			t.Errorf("unexpected error: %s", err.Error())
			continue SuccessLoop
		}

		if !reflect.DeepEqual(expected, got) {
			t.Errorf("wrong output, expected %v but got %v", expected, got)
		}
	}

	fail := map[string]interface{}{
		`pqt: expected to get source argument in format "[1,2,...,N]", but got string1 at index 0`: "[string1,string2]",
		`pqt: expected to get source argument in format "[1,2,...,N]", but got ]`:                  "]",
		`pqt: expected to get source argument in format "[1,2,...,N]", but got [`:                  "[",
		`pqt: expected to get source argument in format "[1,2,...,N]", but got 12412s at index 0`:  "[12412s]",
		`pqt: expected to get source argument in format "[1,2,...,N]", but got {1,2,3}`:            "{1,2,3}",
		`pqt: expected to get source argument in format "[1,2,...,N]", but got (1,2,3)`:            "(1,2,3)",
	}

FailLoop:
	for expected, src := range fail {
		var got pqt.JSONArrayInt64

		err := got.Scan(src)
		if err == nil {
			t.Error("expected error, got nil")
			continue FailLoop
		}
		if expected != err.Error() {
			t.Errorf("undexpected error, got:\n	%s\nbut expected:\n	%s", err.Error(), expected)
		}
	}
}