diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml new file mode 100644 index 0000000..6331d9f --- /dev/null +++ b/.github/workflows/go.yaml @@ -0,0 +1,56 @@ +name: Run Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --verbose + + test: + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + + - name: Checkout Code + uses: actions/checkout@v4 + + - uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Run Tests + run: | + go test ./... -v -covermode=atomic -coverprofile=coverage.out + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 19866d8..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,19 +0,0 @@ -on: - push: - branches: [ "**" ] - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - - name: Get dependencies - run: go mod download - - - name: Run test - run: go test diff --git a/jwt.go b/jwt.go index 5d2217a..3d4aa60 100644 --- a/jwt.go +++ b/jwt.go @@ -179,7 +179,6 @@ func TryVerify(realm string) func(c *gin.Context) { c.Set("claims", token.PrivateClaims()) c.Next() - return } } @@ -209,7 +208,6 @@ func MustVerify(realm string) func(c *gin.Context) { c.Set("claims", token.PrivateClaims()) c.Next() - return } } diff --git a/jwt_test.go b/jwt_test.go index 01dbe12..63e34b5 100644 --- a/jwt_test.go +++ b/jwt_test.go @@ -43,22 +43,18 @@ func TestMain(m *testing.M) { if err := jwt.SetUp(jwt.Option{Realm: rsRealm, SigningAlgorithm: jwt.RS256, PrivKeyBytes: privateKeyBytes}); err != nil { panic(fmt.Errorf("failed to set up: %w", err)) - return } if err := jwt.SetUp(jwt.Option{Realm: rsRealm2, SigningAlgorithm: jwt.RS256, PrivKeyBytes: privateKeyBytes}); err != nil { panic(fmt.Errorf("failed to set up: %w", err)) - return } if err := jwt.SetUp(jwt.Option{Realm: hsRealm, SigningAlgorithm: jwt.HS256, SecretKey: []byte("secret")}); err != nil { panic(fmt.Errorf("failed to set up: %w", err)) - return } if err := jwt.SetUp(jwt.Option{Realm: hsRealm2, SigningAlgorithm: jwt.HS256, SecretKey: []byte("secret")}); err != nil { panic(fmt.Errorf("failed to set up: %w", err)) - return } if err := jwt.SetUp( @@ -70,7 +66,6 @@ func TestMain(m *testing.M) { }, ); err != nil { panic(fmt.Errorf("failed to set up: %w", err)) - return } os.Exit(m.Run()) diff --git a/setup.go b/setup.go index 47b68b7..492b7f1 100644 --- a/setup.go +++ b/setup.go @@ -6,7 +6,7 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" + "os" "time" ) @@ -49,7 +49,7 @@ func setRsaPrivateKey(option *Option) error { if len(option.PrivKeyBytes) > 0 { privKeyBytes = option.PrivKeyBytes } else if option.PrivKeyFile != "" { - privKeyBytes, err = ioutil.ReadFile(option.PrivKeyFile) + privKeyBytes, err = os.ReadFile(option.PrivKeyFile) if err != nil { return fmt.Errorf("failed to read file: %s", option.PrivKeyFile) }