A golang, rust, csharp fetch csv file parser with postgres db
- Testing with a valid URL and database connection string
- Testing with an invalid URL
- Testing with an invalid database connection string
- go test
Data inserted successfully!
Data inserted successfully!
--- FAIL: TestProcessCSVData (0.62s)
main_test.go:15: Expected an error, but got none
FAIL
exit status 1
FAIL csv_parser 0.995s
- Use go run main.go --web to expose :8080/api service
In these test functions, we create sample data for each test case and call the function being tested with the sample data. We then use assertions to check ## that the function behaves correctly for each test case.
- Nuget [ https://www.nuget.org/packages/NUnit]
- dotnet add package NUnit --version 3.13.3
- NUnit testing [https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-nunit]
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 2, Skipped: 0, Total: 2, Duration: 814 ms - /Users/ardeshir/Golang-Rust-Csharp-Comparison/csharp/CsvParser.Tests/bin/Debug/net6.0/CsvParserTests.dll (net6.0)
- Evolving the CLI to also run a Web Service with --web (or basic cli --url)
- The webservice --web listense for param url /CsvParser?url=https://ardeshir.io.file.csv
- (for extra points, no guarantee of support ;P)
- python3 -m venv env
- source env/bin/activate
- pip install psycopg2-binary requests Flask
- python3 csv_parser.py --url https://www.ardeshir.io/file.csv --web
- navigate to http://127.0.0.1:5000/api
- pip install pytest pytest-cov
- pytest --cov=csv_parser tests/
============ test session starts =======================
Data inserted successfully!
---------- coverage: platform darwin, python 3.11.1-final-0 ----------
Name Stmts Miss Cover
-----------------------------------
csv_parser.py 58 15 74%
-----------------------------------
TOTAL 58 15 74%
===============short test summary info =======================
FAILED tests/test_csv_parser.py::test_print_table_api - AssertionError: assert 'id: 1' in 'Table: api\nid: 32 url: http://example.com name: Example API created: 1234567890 \n'
FAILED tests/test_csv_parser.py::test_process_csv_data - AssertionError: assert 7 == 3
(nvm is my choice of node manager)
- nvm install v18
- npm init
- npm install -g ts-node
- npm install --save express
- npm install -g request
- npm install --save-dev @types/request
- npm install -g typescript
- npm install --save yargs
- npm install --save pg csv-parser jsonfile
- npm install --save-dev prettier
- prettier --write src/*.ts.
- npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
- eslint --fix src/.ts | eslint src/.ts
- npm install
- npx ts-node src/csv_parser.ts --web
Table: api
Data inserted successfully!
- To compile and run the code, you will need to follow the following steps:
- Install the required dependencies:
- libcurl: sudo apt-get install libcurl4-openssl-dev
- libpq: sudo apt-get install libpq-dev
- jansson: sudo apt-get install libjansson-dev
- Create a Makefile with the following content:
CC = clang
CFLAGS = -Wall -Wextra -pedantic -std=c11 -O2
LDFLAGS = -lcurl -lpq -ljansson
TARGET = program
all: $(TARGET)
$(TARGET): main.c
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
clean:
rm -f $(TARGET)
- Save the C code to a file named main.c.
- Run make command to compile the code.
- Run the compiled program by typing ./program in the terminal.
- If you want to pass a URL to process the CSV data from, you can pass it as a command-line argument.
- For example, ./main https://www.example.com/file.csv
- If you want to run the program as a web service, pass --web as a command-line argument. For example, ./main --web.