IBM / go-sdk-core

The go-sdk-core repository contains core functionality required by Go code generated by the IBM OpenAPI SDK Generator.
Apache License 2.0
30 stars 24 forks source link

test: use `t.Setenv` to set env vars #180

Closed Juneezee closed 1 year ago

Juneezee commented 1 year ago

Starting from Go 1.17, we can use t.Setenv to set environment variable in test. The environment variable is automatically restored to its original value when the test and all its subtests complete. This ensures that each test does not start with leftover environment variables from previous completed tests.

Reference: https://pkg.go.dev/testing#T.Setenv

func TestFoo(t *testing.T) {
    // before
    os.Setenv(key, "new value")
    defer os.Unsetenv(key)

    // after
    t.Setenv(key, "new value")
}
CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

Juneezee commented 1 year ago

@Juneezee Just out of curiosity... how did you become aware of this library?

Hi @padamstx, thanks for reviewing this PR :smile: . This repository appeared on my Explore page (https://github.com/explore) a few days ago.

Do you by chance use an SDK to access IBM Cloud services?

I've only used SDKs to access AWS and GCP.

padamstx commented 1 year ago

Ha! I've used git for a lot of years and never knew about that "explore" page :joy:

ibm-devx-sdk commented 1 year ago

:tada: This PR is included in version 5.13.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: