diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 92baf4d..c12cc60 100644 --- a/.github/workflows/workflow.yml +++ b/.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 diff --git a/.gitignore b/.gitignore index 2b8d456..7db37c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.test *.out annotate.json +profile.cov diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..8c82a76 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,7 @@ +# Options for analysis running. +run: + timeout: 1m + +linters-settings: + gofmt: + simplify: true diff --git a/README.md b/README.md index 3ce9a41..fc9616e 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 diff --git a/fixtures/quoted.env b/fixtures/quoted.env index 1092b76..0b5d68f 100644 --- a/fixtures/quoted.env +++ b/fixtures/quoted.env @@ -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 +" diff --git a/gotenv.go b/gotenv.go index 4b8c84e..b7a83be 100644 --- a/gotenv.go +++ b/gotenv.go @@ -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) { diff --git a/gotenv_test.go b/gotenv_test.go index 30be166..cf8401e 100644 --- a/gotenv_test.go +++ b/gotenv_test.go @@ -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 +`, }, }, { @@ -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)