Skip to content

Commit

Permalink
Fix integration tests to work again:
Browse files Browse the repository at this point in the history
* Update DefaultHTTPTransport calls to take a logger.
* Info requires an option to specify channel.
* 2 in refresh still not happy, unclear why, the req.Body.Reader has good
  data.
  • Loading branch information
hmlanigan committed Oct 22, 2021
1 parent b109c80 commit 0717c37
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion charmhub/find_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *FindClientSuite) TestLiveFindRequest(c *gc.C) {
findPath, err := basePath.Join("find")
c.Assert(err, jc.ErrorIsNil)

apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(), logger)
apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(logger), logger)
restClient := charmhub.NewHTTPRESTClient(apiRequester, nil)

client := charmhub.NewFindClient(findPath, restClient, logger)
Expand Down
10 changes: 4 additions & 6 deletions charmhub/info_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *InfoClientSuite) TestLiveInfoRequest(c *gc.C) {
infoPath, err := basePath.Join("info")
c.Assert(err, jc.ErrorIsNil)

apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(), logger)
apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(logger), logger)
restClient := charmhub.NewHTTPRESTClient(apiRequester, nil)

client := charmhub.NewInfoClient(infoPath, restClient, logger)
Expand All @@ -43,23 +43,21 @@ func (s *InfoClientSuite) TestLiveInfoRequest(c *gc.C) {
}

func (s *InfoClientSuite) TestLiveInfoRequestWithChannelOption(c *gc.C) {
c.Skip("This test only works on staging currently.")

logger := &charmhub.FakeLogger{}

config, err := charmhub.CharmHubConfigFromURL("https://api.staging.charmhub.io", logger)
config, err := charmhub.CharmHubConfig(logger)
c.Assert(err, jc.ErrorIsNil)
basePath, err := config.BasePath()
c.Assert(err, jc.ErrorIsNil)

infoPath, err := basePath.Join("info")
c.Assert(err, jc.ErrorIsNil)

apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(), logger)
apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(logger), logger)
restClient := charmhub.NewHTTPRESTClient(apiRequester, nil)

client := charmhub.NewInfoClient(infoPath, restClient, logger)
response, err := client.Info(context.TODO(), "ubuntu", charmhub.WithChannel("stable"))
response, err := client.Info(context.TODO(), "ubuntu", charmhub.WithInfoChannel("stable"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(response.Name, gc.Equals, "ubuntu")
}
84 changes: 47 additions & 37 deletions charmhub/refresh_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package charmhub_test
package charmhub

import (
"context"
"github.com/kr/pretty"

"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/charmhub"
)

type RefreshClientSuite struct {
Expand All @@ -23,102 +22,113 @@ type RefreshClientSuite struct {
var _ = gc.Suite(&RefreshClientSuite{})

func (s *RefreshClientSuite) TestLiveRefreshRequest(c *gc.C) {
c.Skip("refresh is broken so skip")

logger := &charmhub.FakeLogger{}
c.Skip("It works on the cli with curl using the created req.Body.Reader data.")
logger := &FakeLogger{}

config, err := charmhub.CharmHubConfig(logger)
config, err := CharmHubConfig(logger)
c.Assert(err, jc.ErrorIsNil)
basePath, err := config.BasePath()
c.Assert(err, jc.ErrorIsNil)

refreshPath, err := basePath.Join("refresh")
c.Assert(err, jc.ErrorIsNil)

apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(), logger)
restClient := charmhub.NewHTTPRESTClient(apiRequester, nil)
apiRequester := NewAPIRequester(DefaultHTTPTransport(logger), logger)
restClient := NewHTTPRESTClient(apiRequester, nil)

client := charmhub.NewRefreshClient(refreshPath, restClient, logger)
client := NewRefreshClient(refreshPath, restClient, logger)

charmConfig, err := charmhub.RefreshOne("wordpress", 0, "latest/stable", charmhub.RefreshBase{
Channel: "20.04",
charmConfig, err := RefreshOne("wordpress", 0, "latest/stable", RefreshBase{
Channel: "18.04",
Name: "ubuntu",
Architecture: "amd64",
})
c.Assert(err, jc.ErrorIsNil)
charmConfig = DefineID(c, charmConfig, "mny7cXFEre1BFZQnXyyyIhCHBpiLTRNi")

response, err := client.Refresh(context.TODO(), charmConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(response, gc.HasLen, 1)
c.Assert(response[0].Result, gc.Equals, "refresh")
c.Assert(response[0].Result, gc.Equals, "refresh", gc.Commentf("%s", pretty.Sprint(response)))
}

func (s *RefreshClientSuite) TestLiveRefreshManyRequest(c *gc.C) {
c.Skip("install is not currently wired up, so the test fails")

logger := &charmhub.FakeLogger{}
c.Skip("It works on the cli with curl using the created req.Body.Reader data.")
logger := &FakeLogger{}

config, err := charmhub.CharmHubConfig(logger)
config, err := CharmHubConfig(logger)
c.Assert(err, jc.ErrorIsNil)
basePath, err := config.BasePath()
c.Assert(err, jc.ErrorIsNil)

refreshPath, err := basePath.Join("refresh")
c.Assert(err, jc.ErrorIsNil)

apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(), logger)
restClient := charmhub.NewHTTPRESTClient(apiRequester, nil)
apiRequester := NewAPIRequester(DefaultHTTPTransport(logger), logger)
restClient := NewHTTPRESTClient(apiRequester, nil)

client := charmhub.NewRefreshClient(refreshPath, restClient, logger)
client := NewRefreshClient(refreshPath, restClient, logger)

wordpressConfig, err := charmhub.RefreshOne("wordpress", 16, "latest/stable", charmhub.RefreshBase{
wordpressConfig, err := RefreshOne("wordpress", 0, "latest/stable", RefreshBase{
Name: "ubuntu",
Channel: "20.04",
Channel: "18.04",
Architecture: "amd64",
})
c.Assert(err, jc.ErrorIsNil)
wordpressConfig = DefineID(c, wordpressConfig, "mny7cXFEre1BFZQnXyyyIhCHBpiLTRNi")

mysqlConfig, err := charmhub.RefreshOne("mysql", 1, "latest/stable", charmhub.RefreshBase{
mysqlConfig, err := RefreshOne("mysql", 58, "latest/candidate", RefreshBase{
Name: "ubuntu",
Channel: "20.04",
Channel: "18.04",
Architecture: "amd64",
})
c.Assert(err, jc.ErrorIsNil)
mysqlConfig = DefineID(c, mysqlConfig, "XcESKcQ4R00AM6dOUpCl9YY4QpAEjnXe")

charmsConfig := charmhub.RefreshMany(wordpressConfig, mysqlConfig)
charmsConfig := RefreshMany(wordpressConfig, mysqlConfig)

response, err := client.Refresh(context.TODO(), charmsConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(response, gc.HasLen, 2)
c.Assert(response[0].Result, gc.Equals, "refresh")
c.Assert(response[1].Result, gc.Equals, "refresh")
c.Assert(response[0].Result, gc.Equals, "refresh", gc.Commentf("[0] failed %s", pretty.Sprint(response)))
c.Assert(response[1].Result, gc.Equals, "refresh", gc.Commentf("[1] failed %s", pretty.Sprint(response)))
}

func (s *RefreshClientSuite) TestLiveInstallRequest(c *gc.C) {
c.Skip("install is not currently wired up, so the test fails")
logger := &FakeLogger{}

logger := &charmhub.FakeLogger{}

config, err := charmhub.CharmHubConfig(logger)
config, err := CharmHubConfig(logger)
c.Assert(err, jc.ErrorIsNil)
basePath, err := config.BasePath()
c.Assert(err, jc.ErrorIsNil)

refreshPath, err := basePath.Join("refresh")
c.Assert(err, jc.ErrorIsNil)

apiRequester := charmhub.NewAPIRequester(charmhub.DefaultHTTPTransport(), logger)
restClient := charmhub.NewHTTPRESTClient(apiRequester, nil)
apiRequester := NewAPIRequester(DefaultHTTPTransport(logger), logger)
restClient := NewHTTPRESTClient(apiRequester, nil)

client := charmhub.NewRefreshClient(refreshPath, restClient, logger)
client := NewRefreshClient(refreshPath, restClient, logger)

charmConfig, err := charmhub.InstallOneFromRevision("wordpress", 16, charmhub.RefreshBase{
charmConfig, err := InstallOneFromRevision("wordpress", 0, RefreshBase{
Name: "ubuntu",
Channel: "20.04",
Channel: "18.04",
Architecture: "amd64",
})
c.Assert(err, jc.ErrorIsNil)

response, err := client.Refresh(context.TODO(), charmConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(response[0].Result, gc.Equals, "install")
c.Assert(response[0].Result, gc.Equals, "install", gc.Commentf("%s", pretty.Sprint(response)))
}

func DefineID(c *gc.C, config RefreshConfig, id string) RefreshConfig {
switch t := config.(type) {
case refreshOne:
t.ID = id
return t
default:
c.Fatalf("unexpected config %T", config)
}
return nil
}

0 comments on commit 0717c37

Please sign in to comment.