Ejemplo n.º 1
0
func TestUpdateWithCompositePK(t *testing.T) {
	t.Parallel()

	tx := begin(t)
	defer tx.Rollback()

	semester, err := data.SelectSemesterByPK(tx, 1999, "Fall")
	if err != data.ErrNotFound {
		t.Fatalf("Expected SelectSemesterByPK to return err data.ErrNotFound but it was: %v", err)
	}

	insertedRow := data.Semester{
		Year:        data.Int16{Value: 1999, Status: data.Present},
		Season:      data.String{Value: "Fall", Status: data.Present},
		Description: data.String{Value: "Last of the century", Status: data.Present},
	}

	err = data.InsertSemester(tx, &insertedRow)
	if err != nil {
		t.Fatalf("InsertSemeseter unexpectedly failed: %v", err)
	}

	updateAttrs := &data.Semester{
		Description: data.String{Value: "New value", Status: data.Present},
	}

	data.UpdateSemester(tx,
		insertedRow.Year.Value,
		insertedRow.Season.Value,
		updateAttrs,
	)

	semester, err = data.SelectSemesterByPK(tx, insertedRow.Year.Value, insertedRow.Season.Value)
	if err != nil {
		t.Fatalf("SelectSemesterByPK unexpectedly failed: %v", err)
	}

	if semester.Description != updateAttrs.Description {
		t.Errorf("Expected Description to be %v, but it was %v", updateAttrs.Description, semester.Description)
	}
}
Ejemplo n.º 2
0
func TestDeleteWithCompositePK(t *testing.T) {
	t.Parallel()

	tx := begin(t)
	defer tx.Rollback()

	_, err := data.SelectSemesterByPK(tx, 1999, "Fall")
	if err != data.ErrNotFound {
		t.Fatalf("Expected SelectSemesterByPK to return err data.ErrNotFound but it was: %v", err)
	}

	insertedRow := data.Semester{
		Year:        data.Int16{Value: 1999, Status: data.Present},
		Season:      data.String{Value: "Fall", Status: data.Present},
		Description: data.String{Value: "Last of the century", Status: data.Present},
	}

	err = data.InsertSemester(tx, &insertedRow)
	if err != nil {
		t.Fatalf("InsertSemeseter unexpectedly failed: %v", err)
	}

	_, err = data.SelectSemesterByPK(tx, insertedRow.Year.Value, insertedRow.Season.Value)
	if err != nil {
		t.Fatalf("SelectSemesterByPK unexpectedly failed: %v", err)
	}

	data.DeleteSemester(tx,
		insertedRow.Year.Value,
		insertedRow.Season.Value,
	)

	_, err = data.SelectSemesterByPK(tx, insertedRow.Year.Value, insertedRow.Season.Value)
	if err != data.ErrNotFound {
		t.Fatalf("Expected SelectSemesterByPK to return err data.ErrNotFound but it was: %v", err)
	}
}