Skip to content

Commit

Permalink
[api/copy] simple case test
Browse files Browse the repository at this point in the history
  • Loading branch information
an0rak-dev committed Jul 3, 2024
1 parent 5482087 commit 0a304cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
22 changes: 17 additions & 5 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -38,7 +39,7 @@ func createTestConfig() *os.File {
return nil
}
jsonString, err := json.Marshal(gin.H{
"architectures": []string{},
"architectures": []string{},
"enableMetricsEndpoint": true,
})
if err != nil {
Expand All @@ -48,10 +49,12 @@ func createTestConfig() *os.File {
return file
}

func (s *ApiSuite) SetUpSuite(c *C) {
func (s *ApiSuite) setupContext() error {
aptly.Version = "testVersion"
file := createTestConfig()
c.Assert(file, NotNil)
if nil == file {
return fmt.Errorf("unable to create the test configuration file")
}
s.configFile = file

flags := flag.NewFlagSet("fakeFlags", flag.ContinueOnError)
Expand All @@ -62,10 +65,19 @@ func (s *ApiSuite) SetUpSuite(c *C) {
s.flags = flags

context, err := ctx.NewContext(s.flags)
c.Assert(err, IsNil)
if nil != err {
return err
}

s.context = context
s.router = Router(context)

return nil
}

func (s *ApiSuite) SetUpSuite(c *C) {
err := s.setupContext()
c.Assert(err, IsNil)
}

func (s *ApiSuite) TearDownSuite(c *C) {
Expand Down Expand Up @@ -98,7 +110,7 @@ func (s *ApiSuite) TestGetVersion(c *C) {
response, err := s.HTTPRequest("GET", "/api/version", nil)
c.Assert(err, IsNil)
c.Check(response.Code, Equals, 200)
c.Check(response.Body.String(), Matches, "{\"Version\":\"" + aptly.Version + "\"}")
c.Check(response.Body.String(), Matches, "{\"Version\":\""+aptly.Version+"\"}")
}

func (s *ApiSuite) TestGetReadiness(c *C) {
Expand Down
29 changes: 29 additions & 0 deletions system/t12_api/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,32 @@ def check(self):
self.check_not_in(b"Warnings: ", resp.content)

self.check_equal(self.get("/api/repos/" + repo_name + "/packages?maximumVersion=1").json(), ['Pi386 libboost-program-options-dev 1.62.0.1 7760e62f99c551cb'])


class ReposAPITestCopyPackage(APITest):
"""
POST /api/repos/:name/copy/:src/:file
"""
def check(self):
pkg_name = "libboost-program-options-dev_1.49.0.1_i386"

# Creating origin repo
repo1_name = self.random_name()
self.check_equal(self.post("/api/repos", json={"Name": repo1_name, "Comment": "origin repo"}).status_code, 201)

# Uploading test package
d = self.random_name()
self.check_equal(self.upload(f"/api/files/{d}", f"{pkg_name}.deb").status_code, 200)
resp = self.post_task(f"/api/repos/{repo1_name}/file/{d}")
self.check_equal(resp.json()['State'], TASK_SUCCEEDED)

# Creating target repo
repo2_name = self.random_name()
self.check_equal(self.post("/api/repos", json={"Name": repo2_name, "Comment": "target repo"}).status_code, 201)

# Copy the package
resp = self.post_task(f"/api/repos/{repo2_name}/copy/{repo1_name}/{pkg_name}.deb")
self.check_equal(resp.status_code, 200)
self.check_equal(resp.json()['State'], TASK_SUCCEEDED)
self.check_equal(self.get(f"/api/repos/{repo2_name}/packages").json(),
['Pi386 libboost-program-options-dev 1.49.0.1 918d2f433384e378'])

0 comments on commit 0a304cd

Please sign in to comment.