-
Notifications
You must be signed in to change notification settings - Fork 43
/
marketplace_utils_test.go
55 lines (39 loc) · 1.36 KB
/
marketplace_utils_test.go
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
package marketplace
import (
"net/http"
"testing"
"github.com/dnaeon/go-vcr/recorder"
"github.com/scaleway/scaleway-sdk-go/internal/testhelpers"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/scaleway-sdk-go/utils"
)
func TestGetImageByName(t *testing.T) {
// Setup recorder and scw client
r, err := recorder.NewAsMode("testdata/go-vcr", recorder.ModeReplaying, nil)
if err != nil {
testhelpers.Ok(t, err)
}
defer r.Stop() // Make sure recorder is stopped once done with it
httpClient := &http.Client{Transport: r}
client, err := scw.NewClient(
scw.WithoutAuth(),
scw.WithHTTPClient(httpClient),
)
if err != nil {
testhelpers.Ok(t, err)
}
t.Run("matching input for GetImageByName", func(t *testing.T) {
// Create SDK objects for Scaleway Instance product
marketplaceAPI := NewApi(client)
imageID, err := marketplaceAPI.FindLocalImageIDByName("Docker", utils.ZoneFrPar1, "C1")
testhelpers.Ok(t, err)
// Docker C1 at par1: 45a7e942-1fb0-48c0-bbf6-0acb9af24604
testhelpers.Equals(t, "45a7e942-1fb0-48c0-bbf6-0acb9af24604", imageID)
})
t.Run("non-matching name for GetImageByName", func(t *testing.T) {
// Create SDK objects for Scaleway Instance product
marketplaceAPI := NewApi(client)
_, err := marketplaceAPI.FindLocalImageIDByName("foo-bar-image", "", "")
testhelpers.Assert(t, err != nil, "Should have error")
})
}