Skip to content

Commit

Permalink
Ci improvements (#18)
Browse files Browse the repository at this point in the history
* ci: run a linter on PRs

* refactor: fix inter issues

* test: add some more test cases
  • Loading branch information
luisdavim committed Jun 2, 2022
1 parent 511f5d8 commit 4eee8b5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 6 deletions.
31 changes: 28 additions & 3 deletions .github/workflows/workflow.yml
@@ -1,16 +1,41 @@
---
name: Go workflow
on: [push]
on:
push:
branches:
- "*"
- "*/*"
- "**"
- "!main"
permissions:
contents: read

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-go@v3
with:
go-version: 1.18

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46
args: --timeout 5m

test:
name: Test Go ${{ matrix.go }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
go: ['1.13', '1.14', '1.15', '1.16', '1.17', '1.18']
go: ["1.13", "1.14", "1.15", "1.16", "1.17", "1.18"]
steps:
- name: Go ${{ matrix.go }}
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Checkout source code
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
*.test
*.out
annotate.json
profile.cov
7 changes: 7 additions & 0 deletions .golangci.yaml
@@ -0,0 +1,7 @@
# Options for analysis running.
run:
timeout: 1m

linters-settings:
gofmt:
simplify: true
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -28,7 +28,7 @@ Once loaded you can use `os.Getenv()` to get the value of the variable.

Let's say you have `.env` file:

```
```sh
APP_ID=1234567
APP_SECRET=abcdef
```
Expand Down Expand Up @@ -78,7 +78,6 @@ Besides above functions, `gotenv` also provides another functions that overrides
- `gotenv.OverLoad`
- `gotenv.OverApply`


Here's the example of this overrides behavior:

```go
Expand Down
8 changes: 8 additions & 0 deletions fixtures/quoted.env
Expand Up @@ -9,3 +9,11 @@ OPTION_H="\n"
OPTION_I="some multi-line text
with \"escaped quotes\" and ${OPTION_A} variable"
OPTION_J='some$pecial$1$2!*chars=qweq""e$$\$""'
OPTION_K="
"
OPTION_L="some multi-line text
with \"escaped quotes\"
empty lines

and ${OPTION_A} variable
"
2 changes: 1 addition & 1 deletion gotenv.go
Expand Up @@ -127,7 +127,7 @@ func Read(filename string) (Env, error) {
return strictParse(f, false)
}

//Unmarshal reads a string line by line and returns the valid Env key/value pair of valid variables.
// Unmarshal reads a string line by line and returns the valid Env key/value pair of valid variables.
// It expands the value of a variable from the environment variable but does not set the value to the environment itself.
// This function is returning an error if there are any invalid lines.
func Unmarshal(str string) (Env, error) {
Expand Down
20 changes: 20 additions & 0 deletions gotenv_test.go
Expand Up @@ -200,6 +200,13 @@ THE SOFTWARE.`,
"OPTION_I": `some multi-line text
with "escaped quotes" and 1 variable`,
"OPTION_J": `some$pecial$1$2!*chars=qweq""e$$\$""`,
"OPTION_K": "\n",
"OPTION_L": `some multi-line text
with "escaped quotes"
empty lines
and 1 variable
`,
},
},
{
Expand Down Expand Up @@ -233,6 +240,19 @@ func TestStrictParse(t *testing.T) {
}
}

func TestRead(t *testing.T) {
for _, tt := range fixtures {
env, err := gotenv.Read(tt.filename)
assert.Nil(t, err)

for key, val := range tt.results {
assert.Equal(t, val, env[key])
}

os.Clearenv()
}
}

func TestLoad(t *testing.T) {
for _, tt := range fixtures {
err := gotenv.Load(tt.filename)
Expand Down

0 comments on commit 4eee8b5

Please sign in to comment.