forked from podengo-project/idmsvc-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HMS-3154 test: smoke test for read domain
Implement the smoke test for read domain operation. Signed-off-by: Alejandro Visiedo <[email protected]>
- Loading branch information
Showing
3 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters