github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/charmhub/package_test.go (about)

     1  // Copyright 2020 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package charmhub
     5  
     6  import (
     7  	"io"
     8  	"net/http"
     9  	"net/url"
    10  	"testing"
    11  
    12  	jc "github.com/juju/testing/checkers"
    13  	gc "gopkg.in/check.v1"
    14  
    15  	"github.com/juju/juju/charmhub/path"
    16  )
    17  
    18  //go:generate go run go.uber.org/mock/mockgen -package charmhub -destination client_mock_test.go github.com/juju/juju/charmhub HTTPClient,RESTClient,FileSystem,Logger
    19  
    20  func Test(t *testing.T) {
    21  	gc.TestingT(t)
    22  }
    23  
    24  func MustParseURL(c *gc.C, path string) *url.URL {
    25  	u, err := url.Parse(path)
    26  	c.Assert(err, jc.ErrorIsNil)
    27  	return u
    28  }
    29  
    30  func MustMakePath(c *gc.C, p string) path.Path {
    31  	u := MustParseURL(c, p)
    32  	return path.MakePath(u)
    33  }
    34  
    35  type nopCloser struct {
    36  	io.Reader
    37  }
    38  
    39  func MakeNopCloser(r io.Reader) nopCloser {
    40  	return nopCloser{
    41  		Reader: r,
    42  	}
    43  }
    44  
    45  func (nopCloser) Close() error { return nil }
    46  
    47  func MakeContentTypeHeader(name string) http.Header {
    48  	h := make(http.Header)
    49  	h.Set("content-type", name)
    50  	return h
    51  }
    52  
    53  func MustNewRequest(c *gc.C, path string) *http.Request {
    54  	req, err := http.NewRequest("GET", path, nil)
    55  	c.Assert(err, jc.ErrorIsNil)
    56  
    57  	return req
    58  }