forked from bradfitz/go-tool-cache
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Fixed warnings, added small UT, added CI build (#8)
* Fixed warnings, added small UT, added CI build * fixed golint errors Signed-off-by: or-shachar <[email protected]> --------- Signed-off-by: or-shachar <[email protected]>
- Loading branch information
1 parent
93ff8ec
commit f8a97c7
Showing
13 changed files
with
178 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: stable | ||
check-latest: true | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... | ||
|
||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
args: --timeout 5m | ||
install-mode: "binary" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"maps" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type mapEnv struct { | ||
m map[string]string | ||
} | ||
|
||
var _ Env = &mapEnv{} | ||
|
||
func (m *mapEnv) Get(key string) string { | ||
return m.m[key] | ||
} | ||
|
||
func TestMaybeS3Cache(t *testing.T) { | ||
fullMap := map[string]string{ | ||
envVarS3BucketName: "bucket", | ||
envVarS3CacheRegion: "region", | ||
envVarS3AwsAccessKey: "accessKey", | ||
envVarS3AwsSecretAccessKey: "secretAccessKey", | ||
} | ||
for k := range fullMap { | ||
missingMap := map[string]string{} | ||
maps.Copy(missingMap, fullMap) | ||
delete(missingMap, k) | ||
t.Run("should return nil if "+k+" is missing", func(t *testing.T) { | ||
env := &mapEnv{m: missingMap} | ||
client, err := maybeS3Cache(context.TODO(), env) | ||
assert.NoError(t, err) | ||
assert.Nil(t, client) | ||
}) | ||
} | ||
|
||
t.Run("should return cache if all expected env vars exists", func(t *testing.T) { | ||
env := &mapEnv{ | ||
m: fullMap, | ||
} | ||
client, err := maybeS3Cache(context.TODO(), env) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, client) | ||
}) | ||
} | ||
|
||
func TestMaybeHttpCache(t *testing.T) { | ||
t.Run("should return nil if "+envVarHttpCacheServerBase+" is missing", func(t *testing.T) { | ||
env := &mapEnv{m: map[string]string{}} | ||
client, err := maybeHttpCache(env) | ||
assert.NoError(t, err) | ||
assert.Nil(t, client) | ||
}) | ||
|
||
t.Run("should return cache if "+envVarHttpCacheServerBase+" env vars exists", func(t *testing.T) { | ||
env := &mapEnv{ | ||
m: map[string]string{ | ||
envVarHttpCacheServerBase: "http://localhost:8080", | ||
}, | ||
} | ||
client, err := maybeHttpCache(env) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, client) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.