File: delegation_apply_test.go

package info (click to toggle)
golang-github-mimuret-golang-iij-dpf 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: makefile: 55
file content (73 lines) | stat: -rw-r--r-- 1,837 bytes parent folder | download
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
package core_test

import (
	"context"
	"net/http"

	"github.com/jarcoal/httpmock"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/mimuret/golang-iij-dpf/pkg/api"
	"github.com/mimuret/golang-iij-dpf/pkg/apis/dpf/v1/core"
	"github.com/mimuret/golang-iij-dpf/pkg/testtool"
)

var _ = Describe("delegations", func() {
	var (
		cl    *testtool.TestClient
		err   error
		reqId string
		s     core.DelegationApply
	)
	BeforeEach(func() {
		Expect(err).To(Succeed())
		cl = testtool.NewTestClient("", "http://localhost", nil)
		s = core.DelegationApply{
			ZoneIDs: []string{"m1", "m2"},
		}
	})
	Describe("DelegationApply", func() {
		Context("Apply", func() {
			id1, bs1 := testtool.CreateAsyncResponse()
			BeforeEach(func() {
				httpmock.RegisterResponder(http.MethodPost, "http://localhost/delegations", httpmock.NewBytesResponder(202, bs1))
				reqId, err = cl.Apply(context.Background(), &s, nil)
			})
			AfterEach(func() {
				httpmock.Reset()
			})
			It("returns job_id", func() {
				Expect(err).To(Succeed())
				Expect(reqId).To(Equal(id1))
			})
			It("post json", func() {
				Expect(cl.RequestBody["/delegations"]).To(MatchJSON(`{
							"zone_ids": ["m1","m2"]
						}`))
			})
		})
		Context("SetPathParams", func() {
			BeforeEach(func() {
				err = s.SetPathParams()
			})
			It("nothing todo", func() {
				Expect(err).To(Succeed())
			})
		})
		Context("api.Spec common test", func() {
			var nilSpec *core.DelegationApply
			testtool.TestDeepCopyObject(&s, nilSpec)
			testtool.TestGetName(&s, "delegations")

			Context("GetPathMethod", func() {
				When("action is ActionApply", func() {
					testtool.TestGetPathMethod(&s, api.ActionApply, http.MethodPost, "/delegations")
				})
				When("other", func() {
					testtool.TestGetPathMethod(&s, api.ActionRead, "", "")
				})
			})
		})
	})
})