-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproviders_test.go
More file actions
86 lines (68 loc) · 2.04 KB
/
providers_test.go
File metadata and controls
86 lines (68 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"forge.lthn.ai/core/api/pkg/provider"
"forge.lthn.ai/core/go-scm/manifest"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestProvidersAPI_Name(t *testing.T) {
api := NewProvidersAPI(nil, nil)
assert.Equal(t, "providers-api", api.Name())
}
func TestProvidersAPI_BasePath(t *testing.T) {
api := NewProvidersAPI(nil, nil)
assert.Equal(t, "/api/v1/providers", api.BasePath())
}
func TestProvidersAPI_List_Good_Empty(t *testing.T) {
gin.SetMode(gin.TestMode)
reg := provider.NewRegistry()
rm := NewRuntimeManager(nil)
api := NewProvidersAPI(reg, rm)
router := gin.New()
rg := router.Group(api.BasePath())
api.RegisterRoutes(rg)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/v1/providers", nil)
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
var resp providersResponse
err := json.Unmarshal(w.Body.Bytes(), &resp)
require.NoError(t, err)
assert.Empty(t, resp.Providers)
}
func TestProvidersAPI_List_Good_WithRuntimeProviders(t *testing.T) {
gin.SetMode(gin.TestMode)
reg := provider.NewRegistry()
rm := NewRuntimeManager(nil)
// Simulate a runtime provider.
rm.providers = append(rm.providers, &RuntimeProvider{
Dir: "/tmp/test",
Port: 9999,
Manifest: &manifest.Manifest{
Code: "test-provider",
Name: "Test Provider",
Version: "0.1.0",
Namespace: "test",
},
})
api := NewProvidersAPI(reg, rm)
router := gin.New()
rg := router.Group(api.BasePath())
api.RegisterRoutes(rg)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/v1/providers", nil)
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
var resp providersResponse
err := json.Unmarshal(w.Body.Bytes(), &resp)
require.NoError(t, err)
require.Len(t, resp.Providers, 1)
assert.Equal(t, "test-provider", resp.Providers[0].Name)
assert.Equal(t, "test", resp.Providers[0].BasePath)
assert.Equal(t, "active", resp.Providers[0].Status)
}