Skip to content

Commit

Permalink
Codecov analysis (#302)
Browse files Browse the repository at this point in the history
* Adding coverage
* splitting out windows testing
* pin runners to golang version 1.15.x
* adding codecov badge to readme
  • Loading branch information
jhnlsn committed Nov 9, 2021
1 parent a65503b commit b1e70ad
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 14 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build-test-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

name: build-and-test-windows
on:
push:
branches: [ main, master ]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:

jobs:
windows-unittest:
runs-on: windows-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ~1.15.15

- name: Cache Go
uses: actions/cache@v2
with:
path: |
%LocalAppData%\go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Unit tests
run: go test ./...
24 changes: 15 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Test
name: build-and-test

on:
push:
Expand All @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, macos-latest]
include:
- os: ubuntu-latest
cachepath: |
Expand All @@ -25,16 +25,12 @@ jobs:
cachepath: |
~/Library/Caches/go-build
~/go/pkg/mod
- os: windows-latest
cachepath: |
%LocalAppData%\go-build
~/go/pkg/mod
steps:
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: ~1.15.15
id: go

- name: Configure git with longpath enabled (for windows)
Expand All @@ -59,6 +55,16 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test
working-directory: amazon-cloudwatch-agent

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
verbose: true
directory: ./amazon-cloudwatch-agent/

- name: Build
run: make test build
run: make build
working-directory: amazon-cloudwatch-agent
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ CWAGENT_VERSION
.terraform.*
terraform.*
.terraform/*
coverage.txt
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fmt:
go fmt ./...

test:
CGO_ENABLED=0 go test -v -failfast ./awscsm/... ./cfg/... ./cmd/... ./handlers/... ./internal/... ./logger/... ./logs/... ./metric/... ./plugins/... ./profiler/... ./tool/... ./translator/...
CGO_ENABLED=0 go test -coverprofile coverage.txt -failfast ./awscsm/... ./cfg/... ./cmd/... ./handlers/... ./internal/... ./logger/... ./logs/... ./metric/... ./plugins/... ./profiler/... ./tool/... ./translator/...

integration-test:
go test ./integration/test/... -p 1 -v --tags=integration
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![codecov](https://codecov.io/gh/aws/amazon-cloudwatch-agent/branch/master/graph/badge.svg?token=79VYANUGOM)](https://codecov.io/gh/aws/amazon-cloudwatch-agent)

# Amazon CloudWatch Agent
The Amazon CloudWatch Agent is software developed for the [CloudWatch Agent](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html)

Expand Down
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
target: auto
# adjust accordingly based on how flaky your tests are
# this allows a 5% drop from the previous base commit coverage
threshold: 5%
25 changes: 21 additions & 4 deletions plugins/inputs/logfile/tailersrc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -189,7 +190,7 @@ func TestOffsetDoneCallBack(t *testing.T) {
}
evt.Done()
i++

log.Println(i)
if i == 10 { // Test before first truncate
time.Sleep(1 * time.Second)
b, err := ioutil.ReadFile(statefile.Name())
Expand All @@ -208,11 +209,19 @@ func TestOffsetDoneCallBack(t *testing.T) {

if i == 15 { // Test after first truncate, saved offset should decrease
time.Sleep(1 * time.Second)
log.Println(statefile.Name())
b, err := ioutil.ReadFile(statefile.Name())
log.Println(b)
if err != nil {
t.Errorf("Failed to read state file: %v", err)
}
offset, err := strconv.Atoi(string(bytes.Split(b, []byte("\n"))[0]))
file_parts := bytes.Split(b, []byte("\n"))
log.Println("file_parts: ", file_parts)
file_string := string(file_parts[0])
log.Println("file_string: ", file_string)
offset, err := strconv.Atoi(file_string)
log.Println(offset)
log.Println(err)
if err != nil {
t.Errorf("Failed to parse offset: %v, from '%s'", err, b)
}
Expand Down Expand Up @@ -243,18 +252,26 @@ func TestOffsetDoneCallBack(t *testing.T) {
for i := 0; i < 10; i++ {
fmt.Fprintln(file, logLine("A", 100, time.Now()))
}
log.Println("Wait 1 seconds before truncate")
time.Sleep(1 * time.Second)

// First truncate then write 50 lines (save state should record 505 bytes)

log.Println("Truncate file")
if err := file.Truncate(0); err != nil {
t.Errorf("Failed to truncate log file '%v': %v", file.Name(), err)
}
log.Println("Sleep before write")
time.Sleep(1 * time.Second)
file.Seek(io.SeekStart, 0)
log.Println("Write for 505")
for i := 0; i < 5; i++ {
fmt.Fprintln(file, logLine("B", 100, time.Now()))
}
time.Sleep(1 * time.Second)

log.Println("Wait 5 seconds before truncate")
time.Sleep(5 * time.Second)
log.Println("Truncate then write 20 lines")

// Second truncate then write 20 lines (save state should record 2020 bytes)
if err := file.Truncate(0); err != nil {
Expand All @@ -265,7 +282,7 @@ func TestOffsetDoneCallBack(t *testing.T) {
for i := 0; i < 20; i++ {
fmt.Fprintln(file, logLine("C", 100, time.Now()))
}
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)

// Removal of log file should stop tailersrc
if err := os.Remove(file.Name()); err != nil {
Expand Down

0 comments on commit b1e70ad

Please sign in to comment.