Skip to content

Commit 033f654

Browse files
updated to single workflow and fixed tests
1 parent cc16cc0 commit 033f654

File tree

6 files changed

+129
-89
lines changed

6 files changed

+129
-89
lines changed

.github/workflows/go-queue.yml

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,68 @@ name: go-queue
22

33
on:
44
push:
5-
branches: ["main"]
6-
pull_request:
7-
release:
8-
types: [published]
5+
branches:
6+
- main
7+
paths:
8+
- "./"
9+
- ".github/workflows/go-queue.yml"
10+
11+
env:
12+
LINTER_VERSION: "v1.51.2"
13+
GO_VERSION: "1.19"
914

1015
jobs:
11-
version:
16+
environment:
1217
runs-on: ubuntu-latest
18+
env:
19+
GITHUB_SHA: ${{ github.sha }}
20+
GITHUB_REF: ${{ github.ref }}
1321
steps:
22+
- name: Get git source
23+
run: |
24+
git_source=`echo $GITHUB_REF | sed 's/refs\/heads\///'`
25+
git_source=`echo $git_source | sed 's/refs\/tags\///'`
26+
git_source=`echo $git_source | sed 's/refs\\///'`
27+
echo $git_source
28+
echo "git_source=$git_source" >> $GITHUB_ENV
29+
- name: Get git SHA
30+
run: |
31+
git_sha=`echo $GITHUB_SHA`
32+
echo $git_sha
33+
echo "git_sha=$git_sha" >> $GITHUB_ENV
1434
- name: Checkout repository code
15-
uses: actions/checkout@v2
35+
uses: actions/checkout@v4
1636
- name: Get version
1737
run: |
18-
version=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
19-
echo $version
20-
echo "version=$version" >> $GITHUB_ENV
38+
version_source=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
39+
echo $version_source
40+
echo "version_source=$version_source" >> $GITHUB_ENV
2141
- name: Generate build artifacts
2242
run: |
2343
mkdir -p /tmp
24-
echo ${{ env.version }} >> /tmp/version
44+
echo ${{ env.version_source }} >> /tmp/version_source
45+
echo ${{ env.git_source }} >> /tmp/git_source
46+
echo ${{ env.git_sha }} >> /tmp/git_sha
2547
- name: Upload artifacts
26-
uses: actions/upload-artifact@v2
48+
uses: actions/upload-artifact@v3
2749
with:
2850
name: artifacts
2951
path: |
30-
/tmp/version
52+
/tmp/version_source
53+
/tmp/git_source
54+
/tmp/git_sha
3155
3256
go_lint:
3357
runs-on: ubuntu-latest
3458
steps:
3559
- uses: actions/setup-go@v3
3660
with:
37-
go-version: 1.16
38-
- uses: actions/checkout@v3
61+
go-version: ${{ env.GO_VERSION }}
62+
- uses: actions/checkout@v4
3963
- name: golangci-lint
4064
uses: golangci/golangci-lint-action@v3
4165
with:
42-
version: v1.44.2
66+
version: ${{ env.LINTER_VERSION }}
4367
working-directory: .
4468
args: --verbose
4569

@@ -50,25 +74,25 @@ jobs:
5074
contents: read
5175
steps:
5276
- name: Check out repository code
53-
uses: actions/checkout@v2
77+
uses: actions/checkout@v4
5478
- name: Setup Go
55-
uses: actions/setup-go@v2
79+
uses: actions/setup-go@v4
5680
with:
57-
go-version: 1.16
81+
go-version: ${{ env.GO_VERSION }}
5882
- name: Test go-queue/finite
5983
continue-on-error: true
6084
run: |
6185
cd /home/runner/work/go-queue/go-queue/finite
6286
go mod download
63-
go test -v ./... -coverprofile /tmp/go-queue-finite.out > /tmp/go-queue-finite.log
87+
go test -v ./... -coverprofile /tmp/go-queue-finite.out tee /tmp/go-queue-finite.log
6488
- name: Test go-queue/infinite
6589
continue-on-error: true
6690
run: |
6791
cd /home/runner/work/go-queue/go-queue/infinite
6892
go mod download
69-
go test -v ./... -coverprofile /tmp/go-queue-infinite.out > /tmp/go-queue-infinite.log
93+
go test -v ./... -coverprofile /tmp/go-queue-infinite.out tee /tmp/go-queue-infinite.log
7094
- name: Upload artifacts
71-
uses: actions/upload-artifact@v2
95+
uses: actions/upload-artifact@v3
7296
with:
7397
name: artifacts
7498
path: |
@@ -79,27 +103,26 @@ jobs:
79103
retention-days: 1
80104

81105
git_push_tag:
82-
if: github.ref == 'refs/heads/main'
83-
needs: [go_test, version]
106+
needs: [go_test, environment]
84107
runs-on: ubuntu-latest
85108
permissions:
86109
contents: write
87110
steps:
88111
- name: Download artifacts
89-
uses: actions/download-artifact@v2
112+
uses: actions/download-artifact@v3
90113
with:
91114
name: artifacts
92115
path: /tmp
93116
- name: Get version
94117
run: |
95-
version=`cat /tmp/version`
118+
version=`cat /tmp/version_source`
96119
echo "version=$version" >> $GITHUB_ENV
97120
- name: Check out repository code
98-
uses: actions/checkout@v2
121+
uses: actions/checkout@v4
99122
with:
100123
fetch-depth: "0"
101124
- name: Push/Update go-queue version
102-
uses: anothrNick/github-tag-action@1.36.0
125+
uses: anothrNick/github-tag-action@v1
103126
env:
104127
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105128
WITH_V: true

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this service will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [1.2.3] - 03/19/22
9+
10+
- Fixed the TestQueue test such that it used the example properly and would work even if the items returned was a slice of bytes
11+
- Added additional test cases to TestPeekFromHead to add max-1 and max+1 use cases to confirm functionality of the Peek functions
12+
813
## [1.2.2] - 09/10/22
914

1015
- Added "Must" functions that will block until success

example.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"reflect"
77
)
88

9-
//REFERENCE: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
9+
// REFERENCE: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
1010
func randomString(nLetters ...int) string {
1111
letterRunes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
1212
nLetter := 20
@@ -22,7 +22,7 @@ func randomString(nLetters ...int) string {
2222

2323
type Example struct {
2424
Int int `json:"int,omitempty"`
25-
Float float64 `json:"float,omitempty"`
25+
Float float64 `json:"float,omitempty,string"`
2626
String string `json:"string,omitempty"`
2727
}
2828

@@ -118,7 +118,7 @@ func ExampleFlush(queue Dequeuer) []*Example {
118118
return ExampleConvertMultiple(queue.Flush())
119119
}
120120

121-
//ExampleGenFloat64 will generate a random number of random float values if n is equal to 0
121+
// ExampleGenFloat64 will generate a random number of random float values if n is equal to 0
122122
// not to exceed the constant TestMaxExamples, if n is provided, it will generate that many items
123123
func ExampleGenFloat64(sizes ...int) []*Example {
124124
size := int(rand.Float64() * 100)

infinite/tests/tests.go

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ import (
1212

1313
const casef string = "case: %s"
1414

15-
//TestEnqueue attempt to unit test the enqueue function, in general it confirms the
15+
// TestEnqueue attempt to unit test the enqueue function, in general it confirms the
1616
// behavior, that for an infinite queue, no matter how much data you put into the
1717
// queue, the queue will never overflow and there will be no data loss. This test
1818
// also assumes that the "size" of the queue won't affect the behavior of enqueue
1919
// This test has some "configuration" items that can be "tweaked" for your specific
2020
// queue implementation:
21-
// - rate: this is the rate at which the test will attempt to enqueue/dequeue
22-
// - timeout: this is when the test will "give up"
21+
// - rate: this is the rate at which the test will attempt to enqueue/dequeue
22+
// - timeout: this is when the test will "give up"
23+
//
2324
// Some assumptions this test does make:
24-
// - your queue can handle valid data, as a plus the example data type supports the
25-
// BinaryMarshaller
25+
// - your queue can handle valid data, as a plus the example data type supports the
26+
// BinaryMarshaller
27+
//
2628
// Some assumptions this test won't make:
27-
// - order is maintained
28-
// - the "size" of the queue affects the behavior of enqueue
29+
// - order is maintained
30+
// - the "size" of the queue affects the behavior of enqueue
2931
func TestEnqueue(t *testing.T, rate, timeout time.Duration, newQueue func() interface {
3032
goqueue.Owner
3133
goqueue.Enqueuer
@@ -86,19 +88,21 @@ func TestEnqueue(t *testing.T, rate, timeout time.Duration, newQueue func() inte
8688
}
8789
}
8890

89-
//TestEnqueueMultiple will attempt to unit test the EnqueueMultiple function;
91+
// TestEnqueueMultiple will attempt to unit test the EnqueueMultiple function;
9092
// for an infinite queue, this function will never overflow nor will it return
9193
// items that weren't able to be enqueued.
9294
// This test has some "configuration" items that can be "tweaked" for your specific
9395
// queue implementation:
94-
// - rate: this is the rate at which the test will attempt to enqueue/dequeue
95-
// - timeout: this is when the test will "give up"
96+
// - rate: this is the rate at which the test will attempt to enqueue/dequeue
97+
// - timeout: this is when the test will "give up"
98+
//
9699
// Some assumptions this test does make:
97-
// - your queue can handle valid data, as a plus the example data type supports the
98-
// BinaryMarshaller
100+
// - your queue can handle valid data, as a plus the example data type supports the
101+
// BinaryMarshaller
102+
//
99103
// Some assumptions this test won't make:
100-
// - order is maintained
101-
// - the "size" of the queue affects the behavior of enqueue
104+
// - order is maintained
105+
// - the "size" of the queue affects the behavior of enqueue
102106
func TestEnqueueMultiple(t *testing.T, rate, timeout time.Duration, newQueue func() interface {
103107
goqueue.Owner
104108
goqueue.Enqueuer
@@ -162,20 +166,22 @@ func TestEnqueueMultiple(t *testing.T, rate, timeout time.Duration, newQueue fun
162166
}
163167
}
164168

165-
//TestEnqueueInFront will validate that if there is data in the queue and you attempt to
169+
// TestEnqueueInFront will validate that if there is data in the queue and you attempt to
166170
// enqueue in front, that special "data" will go to the front, while if the queue is empty
167171
// that data will just be "in" the queue (a regular queue if the queue is empty).
168172
// This test has some "configuration" items that can be "tweaked" for your specific
169173
// queue implementation:
170-
// - rate: this is the rate at which the test will attempt to enqueue/dequeue
171-
// - timeout: this is when the test will "give up"
174+
// - rate: this is the rate at which the test will attempt to enqueue/dequeue
175+
// - timeout: this is when the test will "give up"
176+
//
172177
// Some assumptions this test does make:
173-
// - your queue can handle valid data, as a plus the example data type supports the
174-
// BinaryMarshaller
175-
// - your queue maintains order
176-
// - it's safe to use a single instance of your queue for each test case
178+
// - your queue can handle valid data, as a plus the example data type supports the
179+
// BinaryMarshaller
180+
// - your queue maintains order
181+
// - it's safe to use a single instance of your queue for each test case
182+
//
177183
// Some assumptions this test won't make:
178-
// - the "size" of the queue affects the behavior of enqueue
184+
// - the "size" of the queue affects the behavior of enqueue
179185
func TestEnqueueInFront(t *testing.T, rate, timeout time.Duration, newQueue func() interface {
180186
goqueue.Owner
181187
goqueue.Enqueuer
@@ -224,8 +230,7 @@ func TestEnqueueInFront(t *testing.T, rate, timeout time.Duration, newQueue func
224230
item, underflow := goqueue.MustDequeue(q, ctx.Done(), rate)
225231
cancel()
226232
assert.False(t, underflow)
227-
assert.IsType(t, &goqueue.Example{}, item, casef, cDesc)
228-
example, _ := item.(*goqueue.Example)
233+
example := goqueue.ExampleConvertSingle(item)
229234
assert.Equal(t, c.iInFrontValue, example, casef, cDesc)
230235

231236
//flush the queue to empty it
@@ -238,7 +243,7 @@ func TestEnqueueInFront(t *testing.T, rate, timeout time.Duration, newQueue func
238243
}
239244
}
240245

241-
//TestEnqueueEvent will confirm that the signal channels function correctly when data is enqueued,
246+
// TestEnqueueEvent will confirm that the signal channels function correctly when data is enqueued,
242247
// this function for an infinite queue is slightly different because it can't be lossless, there's
243248
// no way to properly implement a buffered channel with an infinite queue
244249
// Some assumptions this test does make:

0 commit comments

Comments
 (0)