Jelajahi Sumber

feat(plugin): mock file server for plugins test

ngjaying 5 tahun lalu
induk
melakukan
7c5c341bc6

+ 3 - 0
plugins/manager.go

@@ -298,6 +298,9 @@ func downloadFile(filepath string, url string) error {
 	if err != nil {
 		return err
 	}
+	if resp.StatusCode != http.StatusOK {
+		return fmt.Errorf("cannot download the file with status: %d %s", resp.StatusCode, resp.Status)
+	}
 	defer resp.Body.Close()
 
 	// Create the file

+ 8 - 1
plugins/manager_test.go

@@ -3,6 +3,8 @@ package plugins
 import (
 	"errors"
 	"fmt"
+	"net/http"
+	"net/http/httptest"
 	"os"
 	"path"
 	"reflect"
@@ -10,7 +12,12 @@ import (
 )
 
 func TestManager_Register(t *testing.T) {
-	const endpoint = "http://127.0.0.1/plugins"
+	s := httptest.NewServer(
+		http.FileServer(http.Dir("testzips")),
+	)
+	defer s.Close()
+	endpoint := s.URL
+
 	data := []struct {
 		t   PluginType
 		n   string

+ 38 - 0
plugins/plugins.http

@@ -0,0 +1,38 @@
+###
+
+POST http://127.0.0.1:9081/plugins/sources
+Content-Type: application/json
+
+{"name":"random2","file":"http://127.0.0.1/plugins/sources/random2.zip","callback":""}
+
+###
+GET http://127.0.0.1:9081/plugins/sources
+
+###
+DELETE http://127.0.0.1:9081/plugins/sources/random2
+
+###
+POST http://127.0.0.1:9081/plugins/sinks
+Content-Type: application/json
+
+{"name":"random2","file":"http://127.0.0.1/plugins/sources/random2.zip","callback":""}
+
+###
+GET http://127.0.0.1:9081/plugins/sinks
+
+###
+DELETE http://127.0.0.1:9081/plugins/sinks/random2
+
+###
+POST http://127.0.0.1:9081/plugins/functions
+Content-Type: application/json
+
+{"name":"random2","file":"http://127.0.0.1/plugins/sources/random2.zip","callback":""}
+
+###
+GET http://127.0.0.1:9081/plugins/functions
+
+###
+DELETE http://127.0.0.1:9081/plugins/functions/random2
+
+###2217

TEMPAT SAMPAH
plugins/testzips/functions/echo.zip


TEMPAT SAMPAH
plugins/testzips/functions/zipMissSo.zip


TEMPAT SAMPAH
plugins/testzips/sinks/file.zip


TEMPAT SAMPAH
plugins/testzips/sinks/zipWrongName.zip


TEMPAT SAMPAH
plugins/testzips/sources/random2.zip


TEMPAT SAMPAH
plugins/testzips/sources/zipMissConf.zip