mirror of
https://github.com/0xERR0R/blocky.git
synced 2026-10-12 02:01:13 +00:00
* extension cleanup & added ginkgo watch * added gcov2lcov * added test explorer and reworked scripts * go mod tidy * use package cache volume * script rework * defined tasks * defined launch * don't try to convert if test was canceld * generate lcov only in devcontainer * disable coverage upload on forks * wip: make lcov * fixed unit tests for parallel * parallel test for lists * fix serve test for parallel * parallel test fixes * deleted accident commit * wip: make lcov * restructured settings location * start script refactoring * added GetProcessPort * fixed parallel ports * race fix * changed port for github runner binding * fixed local list var in test * more local vars in tests fix * less local vars * run test & race parallel * removed invalid error check * fixed error check * less local variables * fixed timing problem * removed gcov2lcov * added generate-lcov * added GINKGO_PROCS to makefile * fixed workflow * run generate-lcov on save *.go * added tooltitude
78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
|
|
"github.com/0xERR0R/blocky/log"
|
|
"github.com/sirupsen/logrus/hooks/test"
|
|
"github.com/spf13/cobra"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Lists command", func() {
|
|
var (
|
|
ts *httptest.Server
|
|
mockFn func(w http.ResponseWriter, _ *http.Request)
|
|
loggerHook *test.Hook
|
|
c *cobra.Command
|
|
err error
|
|
)
|
|
JustBeforeEach(func() {
|
|
ts = testHTTPAPIServer(mockFn)
|
|
})
|
|
JustAfterEach(func() {
|
|
ts.Close()
|
|
})
|
|
BeforeEach(func() {
|
|
mockFn = func(w http.ResponseWriter, _ *http.Request) {}
|
|
loggerHook = test.NewGlobal()
|
|
log.Log().AddHook(loggerHook)
|
|
})
|
|
AfterEach(func() {
|
|
loggerHook.Reset()
|
|
})
|
|
Describe("Call list refresh command", func() {
|
|
When("list refresh is executed", func() {
|
|
BeforeEach(func() {
|
|
c = NewListsCommand()
|
|
c.SetArgs([]string{"refresh"})
|
|
})
|
|
It("should print result", func() {
|
|
err = c.Execute()
|
|
Expect(err).Should(Succeed())
|
|
|
|
Expect(loggerHook.LastEntry().Message).Should(ContainSubstring("OK"))
|
|
})
|
|
})
|
|
When("Server returns 500", func() {
|
|
BeforeEach(func() {
|
|
c = newRefreshCommand()
|
|
c.SetArgs(make([]string, 0))
|
|
mockFn = func(w http.ResponseWriter, _ *http.Request) {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
}
|
|
})
|
|
It("should end with error", func() {
|
|
err = c.Execute()
|
|
Expect(err).Should(HaveOccurred())
|
|
Expect(err.Error()).Should(ContainSubstring("500 Internal Server Error"))
|
|
})
|
|
})
|
|
When("Url is wrong", func() {
|
|
BeforeEach(func() {
|
|
c = newRefreshCommand()
|
|
c.SetArgs(make([]string, 0))
|
|
})
|
|
It("should end with error", func() {
|
|
apiPort = 0
|
|
err = c.Execute()
|
|
Expect(err).Should(HaveOccurred())
|
|
Expect(err.Error()).Should(ContainSubstring("connection refused"))
|
|
})
|
|
})
|
|
})
|
|
})
|