github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/internal/licenseutils/client_test.go (about) 1 package licenseutils 2 3 import ( 4 "context" 5 6 "github.com/docker/licensing" 7 "github.com/docker/licensing/model" 8 ) 9 10 type ( 11 fakeLicensingClient struct { 12 loginViaAuthFunc func(ctx context.Context, username, password string) (authToken string, err error) 13 getHubUserOrgsFunc func(ctx context.Context, authToken string) (orgs []model.Org, err error) 14 getHubUserByNameFunc func(ctx context.Context, username string) (user *model.User, err error) 15 verifyLicenseFunc func(ctx context.Context, license model.IssuedLicense) (res *model.CheckResponse, err error) 16 generateNewTrialSubscriptionFunc func(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) 17 listSubscriptionsFunc func(ctx context.Context, authToken, dockerID string) (response []*model.Subscription, err error) 18 listSubscriptionsDetailsFunc func(ctx context.Context, authToken, dockerID string) (response []*model.SubscriptionDetail, err error) 19 downloadLicenseFromHubFunc func(ctx context.Context, authToken, subscriptionID string) (license *model.IssuedLicense, err error) 20 parseLicenseFunc func(license []byte) (parsedLicense *model.IssuedLicense, err error) 21 storeLicenseFunc func(ctx context.Context, dclnt licensing.WrappedDockerClient, licenses *model.IssuedLicense, localRootDir string) error 22 loadLocalLicenseFunc func(ctx context.Context, dclnt licensing.WrappedDockerClient) (*model.Subscription, error) 23 summarizeLicenseFunc func(*model.CheckResponse, string) *model.Subscription 24 } 25 ) 26 27 func (c *fakeLicensingClient) LoginViaAuth(ctx context.Context, username, password string) (authToken string, err error) { 28 if c.loginViaAuthFunc != nil { 29 return c.loginViaAuthFunc(ctx, username, password) 30 } 31 return "", nil 32 } 33 34 func (c *fakeLicensingClient) GetHubUserOrgs(ctx context.Context, authToken string) (orgs []model.Org, err error) { 35 if c.getHubUserOrgsFunc != nil { 36 return c.getHubUserOrgsFunc(ctx, authToken) 37 } 38 return nil, nil 39 } 40 41 func (c *fakeLicensingClient) GetHubUserByName(ctx context.Context, username string) (user *model.User, err error) { 42 if c.getHubUserByNameFunc != nil { 43 return c.getHubUserByNameFunc(ctx, username) 44 } 45 return nil, nil 46 } 47 48 func (c *fakeLicensingClient) VerifyLicense(ctx context.Context, license model.IssuedLicense) (res *model.CheckResponse, err error) { 49 if c.verifyLicenseFunc != nil { 50 return c.verifyLicenseFunc(ctx, license) 51 } 52 return nil, nil 53 } 54 55 func (c *fakeLicensingClient) GenerateNewTrialSubscription(ctx context.Context, authToken, dockerID, email string) (subscriptionID string, err error) { 56 if c.generateNewTrialSubscriptionFunc != nil { 57 return c.generateNewTrialSubscriptionFunc(ctx, authToken, dockerID, email) 58 } 59 return "", nil 60 } 61 62 func (c *fakeLicensingClient) ListSubscriptions(ctx context.Context, authToken, dockerID string) (response []*model.Subscription, err error) { 63 if c.listSubscriptionsFunc != nil { 64 return c.listSubscriptionsFunc(ctx, authToken, dockerID) 65 } 66 return nil, nil 67 } 68 69 func (c *fakeLicensingClient) ListSubscriptionsDetails(ctx context.Context, authToken, dockerID string) (response []*model.SubscriptionDetail, err error) { 70 if c.listSubscriptionsDetailsFunc != nil { 71 return c.listSubscriptionsDetailsFunc(ctx, authToken, dockerID) 72 } 73 return nil, nil 74 } 75 76 func (c *fakeLicensingClient) DownloadLicenseFromHub(ctx context.Context, authToken, subscriptionID string) (license *model.IssuedLicense, err error) { 77 if c.downloadLicenseFromHubFunc != nil { 78 return c.downloadLicenseFromHubFunc(ctx, authToken, subscriptionID) 79 } 80 return nil, nil 81 } 82 83 func (c *fakeLicensingClient) ParseLicense(license []byte) (parsedLicense *model.IssuedLicense, err error) { 84 if c.parseLicenseFunc != nil { 85 return c.parseLicenseFunc(license) 86 } 87 return nil, nil 88 } 89 90 func (c *fakeLicensingClient) StoreLicense(ctx context.Context, dclnt licensing.WrappedDockerClient, licenses *model.IssuedLicense, localRootDir string) error { 91 if c.storeLicenseFunc != nil { 92 return c.storeLicenseFunc(ctx, dclnt, licenses, localRootDir) 93 94 } 95 return nil 96 } 97 98 func (c *fakeLicensingClient) LoadLocalLicense(ctx context.Context, dclnt licensing.WrappedDockerClient) (*model.Subscription, error) { 99 100 if c.loadLocalLicenseFunc != nil { 101 return c.loadLocalLicenseFunc(ctx, dclnt) 102 103 } 104 return nil, nil 105 } 106 107 func (c *fakeLicensingClient) SummarizeLicense(cr *model.CheckResponse, keyid string) *model.Subscription { 108 if c.summarizeLicenseFunc != nil { 109 return c.summarizeLicenseFunc(cr, keyid) 110 } 111 return nil 112 }