-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d03c56
commit 2036e10
Showing
13 changed files
with
295 additions
and
19 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
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,21 @@ | ||
package fetcher | ||
|
||
import ( | ||
"bisonai.com/orakl/node/pkg/admin/utils" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func start(c *fiber.Ctx) error { | ||
utils.SendMessage(c, "fetcher", "start", nil) | ||
return c.SendString("fetcher started") | ||
} | ||
|
||
func stop(c *fiber.Ctx) error { | ||
utils.SendMessage(c, "fetcher", "stop", nil) | ||
return c.SendString("fetcher stopped") | ||
} | ||
|
||
func refresh(c *fiber.Ctx) error { | ||
utils.SendMessage(c, "fetcher", "refresh", nil) | ||
return c.SendString("fetcher refreshed") | ||
} |
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,13 @@ | ||
package fetcher | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func Routes(router fiber.Router) { | ||
fetcher := router.Group("/fetcher") | ||
|
||
fetcher.Post("/start", start) | ||
fetcher.Post("/stop", stop) | ||
fetcher.Post("/refresh", refresh) | ||
} |
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,89 @@ | ||
//nolint:all | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFetcherStart(t *testing.T) { | ||
app, err := setup() | ||
if err != nil { | ||
t.Fatalf("error setting up test: %v", err) | ||
} | ||
defer cleanup() | ||
defer app.Shutdown() | ||
|
||
channel := appBus.Subscribe("fetcher", 10) | ||
|
||
result, err := RawPostRequest(app, "/api/v1/fetcher/start", nil) | ||
if err != nil { | ||
t.Fatalf("error starting fetcher: %v", err) | ||
} | ||
|
||
assert.Equal(t, string(result), "fetcher started") | ||
|
||
select { | ||
case msg := <-channel: | ||
if msg.From != "admin" || msg.To != "fetcher" || msg.Content.Command != "start" { | ||
t.Fatalf("unexpected message: %v", msg) | ||
} | ||
default: | ||
t.Fatalf("no message received on channel") | ||
} | ||
} | ||
|
||
func TestFetcherStop(t *testing.T) { | ||
app, err := setup() | ||
if err != nil { | ||
t.Fatalf("error setting up test: %v", err) | ||
} | ||
defer cleanup() | ||
defer app.Shutdown() | ||
|
||
channel := appBus.Subscribe("fetcher", 10) | ||
|
||
result, err := RawPostRequest(app, "/api/v1/fetcher/stop", nil) | ||
if err != nil { | ||
t.Fatalf("error stopping fetcher: %v", err) | ||
} | ||
|
||
assert.Equal(t, string(result), "fetcher stopped") | ||
|
||
select { | ||
case msg := <-channel: | ||
if msg.From != "admin" || msg.To != "fetcher" || msg.Content.Command != "stop" { | ||
t.Fatalf("unexpected message: %v", msg) | ||
} | ||
default: | ||
t.Fatalf("no message received on channel") | ||
} | ||
} | ||
|
||
func TestFetcherRefresh(t *testing.T) { | ||
app, err := setup() | ||
if err != nil { | ||
t.Fatalf("error setting up test: %v", err) | ||
} | ||
defer cleanup() | ||
defer app.Shutdown() | ||
|
||
channel := appBus.Subscribe("fetcher", 10) | ||
|
||
result, err := RawPostRequest(app, "/api/v1/fetcher/refresh", nil) | ||
if err != nil { | ||
t.Fatalf("error refreshing fetcher: %v", err) | ||
} | ||
|
||
assert.Equal(t, string(result), "fetcher refreshed") | ||
|
||
select { | ||
case msg := <-channel: | ||
if msg.From != "admin" || msg.To != "fetcher" || msg.Content.Command != "refresh" { | ||
t.Fatalf("unexpected message: %v", msg) | ||
} | ||
default: | ||
t.Fatalf("no message received on channel") | ||
} | ||
} |
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
Oops, something went wrong.