Skip to content

Commit

Permalink
HMS-3154 test: smoke test for read domain
Browse files Browse the repository at this point in the history
Implement the smoke test for read domain operation.

Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo committed Nov 29, 2023
1 parent 9739085 commit 98aae52
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 8 deletions.
7 changes: 0 additions & 7 deletions internal/test/smoke/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ func (s *SuiteListDomains) TearDownTest() {
s.SuiteBase.TearDownTest()
}

// bodyExpectationListDomains is a specific expectation method that fit BodyFuncListDomainsResponse
func (s *SuiteListDomains) bodyExpectationListDomains(t *testing.T, body *public.ListDomainsResponse) error {
// TODO Implement the expectations

return nil
}

func (s *SuiteListDomains) TestListDomains() {
t := s.T()
xrhidEncoded := header.EncodeXRHID(&s.UserXRHID)
Expand Down
88 changes: 88 additions & 0 deletions internal/test/smoke/read_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package smoke

import (
"fmt"
"net/http"
"testing"

"github.com/podengo-project/idmsvc-backend/internal/api/header"
"github.com/podengo-project/idmsvc-backend/internal/api/public"
test_assert "github.com/podengo-project/idmsvc-backend/internal/test/assert"
builder_api "github.com/podengo-project/idmsvc-backend/internal/test/builder/api"
builder_helper "github.com/podengo-project/idmsvc-backend/internal/test/builder/helper"
)

// SuiteReadDomain is the suite to validate the smoke test when read domain endpoint at GET /api/idmsvc/v1/domains/:domain_id
type SuiteReadDomain struct {
SuiteBase
Domains []*public.Domain
}

func (s *SuiteReadDomain) SetupTest() {
s.SuiteBase.SetupTest()

var (
domainName string
domain *public.Domain
err error
i int
)

// Domain 1 in OrgID1
i = 0
s.Domains = []*public.Domain{}
domainName = fmt.Sprintf("domain%d.test", i)
domain, err = s.RegisterIpaDomain(builder_api.NewDomain(domainName).Build())
if err != nil {
s.FailNow("error creating ")
}
s.Domains = append(s.Domains, domain)
}

func (s *SuiteReadDomain) TearDownTest() {
for i := range s.Domains {
s.Domains[i] = nil
}
s.Domains = nil

s.SuiteBase.TearDownTest()
}

func (s *SuiteReadDomain) TestDomain() {
xrhidEncoded := header.EncodeXRHID(&s.UserXRHID)
url := fmt.Sprintf("%s/%s/%s", s.DefaultPublicBaseURL(), "domains", s.Domains[0].DomainId)
domainName := builder_helper.GenRandomDomainName(2)

// Prepare the tests
testCases := []TestCase{
{
Name: "TestReadDomain",
Given: TestCaseGiven{
Method: http.MethodGet,
URL: url,
Header: http.Header{
"X-Rh-Insights-Request-Id": {"test_token"},
"X-Rh-Identity": {xrhidEncoded},
},
Body: builder_api.NewDomain(domainName).Build(),
},
Expected: TestCaseExpect{
// FIXME It must be http.StatusCreated
StatusCode: http.StatusOK,
Header: http.Header{
// FIXME Avoid hardcode the key name of the header
"X-Rh-Insights-Request-Id": {"test_token"},
"X-Rh-Identity": nil,
// TODO Check format for X-Rh-Idm-Version
},
BodyFunc: WrapBodyFuncDomainResponse(func(t *testing.T, body *public.Domain) error {
test_assert.AssertDomain(t, s.Domains[0], body)
return nil
}),
},
},
}

// Execute the test cases
s.RunTestCases(testCases)
}
2 changes: 1 addition & 1 deletion internal/test/smoke/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func TestSuite(t *testing.T) {
suite.Run(t, new(SuiteRegisterDomain))
// suite.Run(t, new(SuiteDomainUpdateUser))
// suite.Run(t, new(SuiteDomainUpdateAgent))
// suite.Run(t, new(SuiteDomainRead))
suite.Run(t, new(SuiteReadDomain))
suite.Run(t, new(SuiteListDomains))
// suite.Run(t, new(SuiteDomainDelete))
}

0 comments on commit 98aae52

Please sign in to comment.