Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit test actions workflow #193

Merged
merged 12 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 31 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: test

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize]


jobs:
unit:
name: unit
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: install dependencies
run: |
pip install cpplint
sudo apt-get install -qq valgrind libcurl4-openssl-dev

- name: build googletest
run: ./utils/build_gtest.sh

- name: build
run: |
./autogen.sh
./configure --enable-coverage

- name: run tests
run: make ci
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ BUILT_SOURCES = include/restclient-cpp/version.h

test_program_SOURCES = vendor/jsoncpp-0.10.5/dist/jsoncpp.cpp test/tests.cpp test/test_helpers.cc test/test_restclient.cc test/test_connection.cc
test_program_LDADD = .libs/librestclient-cpp.a
test_program_LDFLAGS=-Lvendor/gtest-1.7.0/lib/.libs -lgtest
test_program_CPPFLAGS=-std=c++11 -Iinclude -Ivendor/gtest-1.7.0/include -Ivendor/jsoncpp-0.10.5/dist
test_program_LDFLAGS=-Lvendor/googletest-1.14.0/lib -lgtest
test_program_CPPFLAGS=-std=c++14 -Iinclude -Ivendor/googletest-1.14.0/googletest/include -Ivendor/jsoncpp-0.10.5/dist

lib_LTLIBRARIES=librestclient-cpp.la
librestclient_cpp_la_SOURCES=source/restclient.cc source/connection.cc source/helpers.cc
librestclient_cpp_la_CXXFLAGS=-fPIC -std=c++11
librestclient_cpp_la_CXXFLAGS=-fPIC -std=c++14
librestclient_cpp_la_LDFLAGS=-version-info 2:1:1

dist_doc_DATA = README.md

.PHONY: test check clean-coverage-files coverage-html include/restclient-cpp/version.h lint ci docker-services clean-docker-services

include/restclient-cpp/version.h:
m4 -I ${top_srcdir}/m4 -DM4_RESTCLIENT_VERSION=$(PACKAGE_VERSION) version.h.m4 > ${top_srcdir}/$@
m4 -I ${top_srcdir}/m4 -DM4_RESTCLIENT_VERSION=$(PACKAGE_VERSION) version.h.m4 > ${top_srcdir}/$@



test: check docker-services
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# REST client for C++
[![Build Status](https://travis-ci.org/mrtazz/restclient-cpp.svg?branch=master)](https://travis-ci.org/mrtazz/restclient-cpp)
![build status](https://github.com/mrtazz/restclient-cpp/actions/workflows/tests.yaml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/mrtazz/restclient-cpp/badge.svg?branch=master&service=github)](https://coveralls.io/github/mrtazz/restclient-cpp?branch=master)
[![Packagecloud](https://img.shields.io/badge/packagecloud-available-brightgreen.svg)](https://packagecloud.io/mrtazz/restclient-cpp)
[![doxygen](https://img.shields.io/badge/doxygen-reference-blue.svg)](http://code.mrtazz.com/restclient-cpp/ref/)
Expand Down Expand Up @@ -161,7 +161,7 @@ reuse connections][curl_keepalive] made with that handle.

### Progress callback

Two wrapper functions are provided to setup the progress callback for uploads/downloads.
Two wrapper functions are provided to setup the progress callback for uploads/downloads.

Calling `conn->SetFileProgressCallback(callback)` with a callback parameter matching the prototype `int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)` will setup the progress callback.

Expand Down
18 changes: 10 additions & 8 deletions test/test_restclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TEST_F(RestClientTest, TestRestClientDELETEFailureCode)
{
std::string u = RestClient::TestNonExistantUrl;
RestClient::Response res = RestClient::del(u);
// 6 = CURLE_COULDNT_RESOLVE_HOST
// 6 = CURLE_COULDNT_RESOLVE_HOST
EXPECT_EQ(6, res.code);
}

Expand All @@ -71,8 +71,9 @@ TEST_F(RestClientTest, TestRestClientGETCode)

TEST_F(RestClientTest, TestRestClientGETHTTP2Code)
{
RestClient::Response res = RestClient::get("https://http2.golang.org/reqinfo");
EXPECT_EQ(200, res.code);
// the endpoint does a redirect now
RestClient::Response res = RestClient::get("https://http2.golang.org");
EXPECT_EQ(302, res.code);
}

TEST_F(RestClientTest, TestRestClientGETBodyCode)
Expand All @@ -92,7 +93,7 @@ TEST_F(RestClientTest, TestRestClientGETFailureCode)
std::string u = RestClient::TestNonExistantUrl;
RestClient::Response res = RestClient::get(u);
EXPECT_EQ("Couldn't resolve host name", res.body);
// 6 = CURLE_COULDNT_RESOLVE_HOST
// 6 = CURLE_COULDNT_RESOLVE_HOST
EXPECT_EQ(6, res.code);
}

Expand Down Expand Up @@ -126,7 +127,7 @@ TEST_F(RestClientTest, TestRestClientPOSTFailureCode)
{
std::string u = RestClient::TestNonExistantUrl;
RestClient::Response res = RestClient::post(u, "text/text", "data");
// 6 = CURLE_COULDNT_RESOLVE_HOST
// 6 = CURLE_COULDNT_RESOLVE_HOST
EXPECT_EQ(6, res.code);
}

Expand Down Expand Up @@ -160,7 +161,7 @@ TEST_F(RestClientTest, TestRestClientPUTFailureCode)
{
std::string u = RestClient::TestNonExistantUrl;
RestClient::Response res = RestClient::put(u, "text/text", "data");
// 6 = CURLE_COULDNT_RESOLVE_HOST
// 6 = CURLE_COULDNT_RESOLVE_HOST
EXPECT_EQ(6, res.code);
}

Expand Down Expand Up @@ -194,7 +195,7 @@ TEST_F(RestClientTest, TestRestClientPATCHFailureCode)
{
std::string u = RestClient::TestNonExistantUrl;
RestClient::Response res = RestClient::patch(u, "text/text", "data");
// 6 = CURLE_COULDNT_RESOLVE_HOST
// 6 = CURLE_COULDNT_RESOLVE_HOST
EXPECT_EQ(6, res.code);
}

Expand All @@ -209,6 +210,7 @@ TEST_F(RestClientTest, TestRestClientPATCHHeaders)
// Disabled as httpbin does not support options requests for now
TEST_F(RestClientTest, TestRestClientOPTIONSCode)
{
GTEST_SKIP();
RestClient::Response res = RestClient::options("https://api.reqbin.com/api/v1/requests");
EXPECT_EQ(200, res.code);
}
Expand All @@ -218,7 +220,7 @@ TEST_F(RestClientTest, TestRestClientOPTIONSFailureCode)
{
std::string u = RestClient::TestNonExistantUrl;
RestClient::Response res = RestClient::options(u);
// 6 = CURLE_COULDNT_RESOLVE_HOST
// 6 = CURLE_COULDNT_RESOLVE_HOST
EXPECT_EQ(6, res.code);
}

Expand Down
6 changes: 2 additions & 4 deletions utils/build_gtest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/sh
cd vendor/gtest-1.7.0
autoreconf -i
./configure

cd vendor/googletest-1.14.0
cmake .
which -s gmake && gmake || make
4 changes: 4 additions & 0 deletions vendor/googletest-1.14.0/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Run manually to reformat a file:
# clang-format -i --style=file <file>
Language: Cpp
BasedOnStyle: Google
53 changes: 53 additions & 0 deletions vendor/googletest-1.14.0/.github/ISSUE_TEMPLATE/00-bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Bug Report
description: Let us know that something does not work as expected.
title: "[Bug]: Please title this bug report"
body:
- type: textarea
id: what-happened
attributes:
label: Describe the issue
description: What happened, and what did you expect to happen?
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps to reproduce the problem
description: It is important that we are able to reproduce the problem that you are experiencing. Please provide all code and relevant steps to reproduce the problem, including your `BUILD`/`CMakeLists.txt` file and build commands. Links to a GitHub branch or [godbolt.org](https://godbolt.org/) that demonstrate the problem are also helpful.
validations:
required: true
- type: textarea
id: version
attributes:
label: What version of GoogleTest are you using?
description: Please include the output of `git rev-parse HEAD` or the GoogleTest release version number that you are using.
validations:
required: true
- type: textarea
id: os
attributes:
label: What operating system and version are you using?
description: If you are using a Linux distribution please include the name and version of the distribution as well.
validations:
required: true
- type: textarea
id: compiler
attributes:
label: What compiler and version are you using?
description: Please include the output of `gcc -v` or `clang -v`, or the equivalent for your compiler.
validations:
required: true
- type: textarea
id: buildsystem
attributes:
label: What build system are you using?
description: Please include the output of `bazel --version` or `cmake --version`, or the equivalent for your build system.
validations:
required: true
- type: textarea
id: additional
attributes:
label: Additional context
description: Add any other context about the problem here.
validations:
required: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Feature request
description: Propose a new feature.
title: "[FR]: Please title this feature request"
labels: "enhancement"
body:
- type: textarea
id: version
attributes:
label: Does the feature exist in the most recent commit?
description: We recommend using the latest commit from GitHub in your projects.
validations:
required: true
- type: textarea
id: why
attributes:
label: Why do we need this feature?
description: Ideally, explain why a combination of existing features cannot be used instead.
validations:
required: true
- type: textarea
id: proposal
attributes:
label: Describe the proposal.
description: Include a detailed description of the feature, with usage examples.
validations:
required: true
- type: textarea
id: platform
attributes:
label: Is the feature specific to an operating system, compiler, or build system version?
description: If it is, please specify which versions.
validations:
required: true
5 changes: 5 additions & 0 deletions vendor/googletest-1.14.0/.github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Get Help
url: https://github.com/google/googletest/discussions
about: Please ask and answer questions here.
43 changes: 43 additions & 0 deletions vendor/googletest-1.14.0/.github/workflows/gtest-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: ci

on:
push:
pull_request:

env:
BAZEL_CXXOPTS: -std=c++14

jobs:
Linux:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Tests
run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ...

macOS:
runs-on: macos-latest
steps:

- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Tests
run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ...


Windows:
runs-on: windows-latest
steps:

- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Tests
run: bazel test --cxxopt=/std:c++14 --features=external_include_paths --test_output=errors ...
Loading