-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: register plugins via init function
- Loading branch information
1 parent
48ee683
commit 4888dc2
Showing
7 changed files
with
90 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/sundowndev/phoneinfoga/v2/lib/number" | ||
"github.com/sundowndev/phoneinfoga/v2/lib/remote" | ||
"testing" | ||
) | ||
|
||
func TestCustomScanner(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
number *number.Number | ||
expected customScannerResponse | ||
wantError string | ||
}{ | ||
{ | ||
name: "test successful scan", | ||
number: func() *number.Number { | ||
n, _ := number.NewNumber("15556661212") | ||
return n | ||
}(), | ||
expected: customScannerResponse{ | ||
Valid: true, | ||
Info: "This number is known for scams!", | ||
Hidden: "This will not appear in the output", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range testcases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
scanner := &customScanner{} | ||
|
||
remoteLib := remote.NewLibrary() | ||
remoteLib.AddScanner(scanner) | ||
|
||
if !scanner.ShouldRun(*tt.number) { | ||
t.Fatal("ShouldRun() should be truthy") | ||
} | ||
|
||
got, err := scanner.Scan(*tt.number) | ||
if tt.wantError != "" { | ||
assert.EqualError(t, err, tt.wantError) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
assert.Equal(t, tt.expected, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters