From d4bd35c3d3b44fcd69673ac8783a5ac315f320d0 Mon Sep 17 00:00:00 2001 From: PandaJW <5168pandayoyo@gmail.com> Date: Wed, 19 Jun 2024 00:43:28 +0800 Subject: [PATCH] removing testing for test database --- database_test.go | 162 +++++++++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/database_test.go b/database_test.go index 7a282f9..ddd2578 100644 --- a/database_test.go +++ b/database_test.go @@ -13,87 +13,87 @@ import ( ) // Test using test database -func TestDatabase(t *testing.T) { - ctx := context.Background() - - // configure database URL - conf := &firebase.Config{ - DatabaseURL: "https://edusync-test-default-rtdb.firebaseio.com/", - } - - // fetch service account key - opt := option.WithCredentialsFile("edusync-test-firebase-adminsdk-hk5kl-9af0162b09.json") - - app, err := firebase.NewApp(ctx, conf, opt) - if err != nil { - t.Errorf("error in initializing firebase app: %v", err) - } - - client, err := app.Database(ctx) - if err != nil { - t.Errorf("error in creating firebase DB client: %v", err) - } - - // create ref at path students/:userId - ref := client.NewRef("students/" + fmt.Sprint(1)) - - // Test case 1: Successful set operation - data := map[string]interface{}{ - "name": "Jane Doe", - "age": "7", - "class": "Tech Explorer", - "instructor": "Scott Smith", - } - if err := ref.Set(ctx, data); err != nil { - t.Errorf("error in setting data: %v", err) - } - - // Test case 2: Get the set data - var getData map[string]interface{} - if err := ref.Get(ctx, &getData); err != nil { - t.Errorf("error in getting data: %v", err) - } - if getData["name"] != "Jane Doe" { - t.Errorf("expected name to be 'Jane Doe', got %v", getData["name"]) - } - - // Test case 3: Update the data - updateData := map[string]interface{}{ - "name": "John Doe", - } - if err := ref.Update(ctx, updateData); err != nil { - t.Errorf("error in updating data: %v", err) - } - - // Test case 4: Get the updated data - var updatedData map[string]interface{} - if err := ref.Get(ctx, &updatedData); err != nil { - t.Errorf("error in getting updated data: %v", err) - } - if updatedData["name"] != "John Doe" { - t.Errorf("expected name to be 'John Doe', got %v", updatedData["name"]) - } - - // Test case 5: Delete the data - if err := ref.Delete(ctx); err != nil { - t.Errorf("error in deleting data: %v", err) - } - - // Test case 6: Get the deleted data (should return an error) - var deletedData map[string]interface{} - // if err := ref.Get(ctx, &deletedData); err == nil { - // t.Errorf("expected error in getting deleted data, but got nil") - // } - if err := ref.Get(ctx, &deletedData); err == nil { - // If no error, check if the data is actually deleted - if deletedData != nil { - t.Errorf("Expected data to be deleted, but got %v", deletedData) - } - } else { - // Expecting an error, which indicates the data was not found - t.Logf("Received expected error after deletion: %v", err) - } -} +// func TestDatabase(t *testing.T) { +// ctx := context.Background() + +// // configure database URL +// conf := &firebase.Config{ +// DatabaseURL: "https://edusync-test-default-rtdb.firebaseio.com/", +// } + +// // fetch service account key +// opt := option.WithCredentialsFile("edusync-test-firebase-adminsdk-hk5kl-9af0162b09.json") + +// app, err := firebase.NewApp(ctx, conf, opt) +// if err != nil { +// t.Errorf("error in initializing firebase app: %v", err) +// } + +// client, err := app.Database(ctx) +// if err != nil { +// t.Errorf("error in creating firebase DB client: %v", err) +// } + +// // create ref at path students/:userId +// ref := client.NewRef("students/" + fmt.Sprint(1)) + +// // Test case 1: Successful set operation +// data := map[string]interface{}{ +// "name": "Jane Doe", +// "age": "7", +// "class": "Tech Explorer", +// "instructor": "Scott Smith", +// } +// if err := ref.Set(ctx, data); err != nil { +// t.Errorf("error in setting data: %v", err) +// } + +// // Test case 2: Get the set data +// var getData map[string]interface{} +// if err := ref.Get(ctx, &getData); err != nil { +// t.Errorf("error in getting data: %v", err) +// } +// if getData["name"] != "Jane Doe" { +// t.Errorf("expected name to be 'Jane Doe', got %v", getData["name"]) +// } + +// // Test case 3: Update the data +// updateData := map[string]interface{}{ +// "name": "John Doe", +// } +// if err := ref.Update(ctx, updateData); err != nil { +// t.Errorf("error in updating data: %v", err) +// } + +// // Test case 4: Get the updated data +// var updatedData map[string]interface{} +// if err := ref.Get(ctx, &updatedData); err != nil { +// t.Errorf("error in getting updated data: %v", err) +// } +// if updatedData["name"] != "John Doe" { +// t.Errorf("expected name to be 'John Doe', got %v", updatedData["name"]) +// } + +// // Test case 5: Delete the data +// if err := ref.Delete(ctx); err != nil { +// t.Errorf("error in deleting data: %v", err) +// } + +// // Test case 6: Get the deleted data (should return an error) +// var deletedData map[string]interface{} +// // if err := ref.Get(ctx, &deletedData); err == nil { +// // t.Errorf("expected error in getting deleted data, but got nil") +// // } +// if err := ref.Get(ctx, &deletedData); err == nil { +// // If no error, check if the data is actually deleted +// if deletedData != nil { +// t.Errorf("Expected data to be deleted, but got %v", deletedData) +// } +// } else { +// // Expecting an error, which indicates the data was not found +// t.Logf("Received expected error after deletion: %v", err) +// } +// } // Test using actual database func TestDatabaseCRUD(t *testing.T) {