Skip to content

Commit

Permalink
Merge pull request #1 from iamelevich/validate-context
Browse files Browse the repository at this point in the history
Add context nil validation
  • Loading branch information
iamelevich authored Mar 19, 2023
2 parents 3326f38 + ef18eda commit 7bb351f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

![Coverage](https://img.shields.io/badge/Coverage-58.8%25-yellow)
![Coverage](https://img.shields.io/badge/Coverage-21.1%25-red)
<!-- TOC -->
* [Overview](#overview)
* [Requirements](#requirements)
Expand Down
8 changes: 8 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ type Plugin struct {
}

func (p *Plugin) Validate() error {
if p.options == nil {
return fmt.Errorf("options is required")
}

if p.options.Ctx == nil {
return fmt.Errorf("context is required")
}

if p.app == nil {
return fmt.Errorf("app is required")
}
Expand Down
17 changes: 17 additions & 0 deletions plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pocketbase_plugin_ngrok

import (
"context"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
"testing"
Expand All @@ -21,6 +22,19 @@ func TestPlugin_Validate(t *testing.T) {
fields: fields{
app: nil,
options: &Options{
Ctx: context.Background(),
Enabled: true,
AuthToken: "",
},
},
wantErr: true,
},
{
name: "Context is nil",
fields: fields{
app: pocketbase.New(),
options: &Options{
Ctx: nil,
Enabled: true,
AuthToken: "",
},
Expand All @@ -32,6 +46,7 @@ func TestPlugin_Validate(t *testing.T) {
fields: fields{
app: pocketbase.New(),
options: &Options{
Ctx: context.Background(),
Enabled: true,
AuthToken: "",
},
Expand All @@ -43,6 +58,7 @@ func TestPlugin_Validate(t *testing.T) {
fields: fields{
app: pocketbase.New(),
options: &Options{
Ctx: context.Background(),
Enabled: false,
AuthToken: "",
},
Expand All @@ -54,6 +70,7 @@ func TestPlugin_Validate(t *testing.T) {
fields: fields{
app: pocketbase.New(),
options: &Options{
Ctx: context.Background(),
Enabled: true,
AuthToken: "TEST_AUTH_TOKEN",
},
Expand Down

0 comments on commit 7bb351f

Please sign in to comment.