From 83b630c6c7ee8fa87f4e6262fb62d59440d0e90d Mon Sep 17 00:00:00 2001 From: roneli <38083777+roneli@users.noreply.github.com> Date: Mon, 7 Feb 2022 17:38:23 +0200 Subject: [PATCH 1/8] fix: New release not found while building while creating a new release, the tag is created but the binary hasn't compiled yet, we want to avoid this by fetching the prior release until all assets are added. --- pkg/plugin/registry/hub.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/plugin/registry/hub.go b/pkg/plugin/registry/hub.go index 35dad71a00f208..a5f26c9ce781b0 100644 --- a/pkg/plugin/registry/hub.go +++ b/pkg/plugin/registry/hub.go @@ -275,8 +275,20 @@ func (h Hub) getRelease(ctx context.Context, organization, providerName, version release, _, err := client.Repositories.GetReleaseByTag(ctx, organization, ProviderRepoName(providerName), version) return release, err } - release, _, err := client.Repositories.GetLatestRelease(ctx, organization, ProviderRepoName(providerName)) - return release, err + releases, _, err := client.Repositories.ListReleases(ctx, organization, ProviderRepoName(providerName), &github.ListOptions{ + Page: 0, + PerPage: 2, + }) + if err != nil { + return nil, err + } + if len(releases) == 1 { + return releases[0], nil + } + if len(releases[0].Assets) < len(releases[1].Assets) { + return releases[1], nil + } + return releases[0], nil } func (h Hub) verifyRegistered(organization, providerName, version string, noVerify bool) bool { From 2b45d414444d7fd5c244fe15e03b60523a2a7bdc Mon Sep 17 00:00:00 2001 From: roneli <38083777+roneli@users.noreply.github.com> Date: Wed, 9 Feb 2022 17:02:18 +0200 Subject: [PATCH 2/8] try firebase --- go.mod | 3 +- go.sum | 1 + pkg/plugin/registry/hub.go | 62 ++++++++++++++------------------------ 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/go.mod b/go.mod index ad4d52e9c04ab3..9426a60503023b 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( ) require ( + cloud.google.com/go/firestore v1.1.0 github.com/ProtonMail/go-crypto v0.0.0-20211221144345-a4f6767435ab github.com/aws/aws-sdk-go v1.42.1 github.com/creasty/defaults v1.5.2 @@ -55,6 +56,7 @@ require ( go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.2.0 go.opentelemetry.io/otel/sdk v1.2.0 go.opentelemetry.io/otel/trace v1.2.0 + google.golang.org/api v0.51.0 google.golang.org/grpc v1.42.0 ) @@ -132,7 +134,6 @@ require ( golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.5 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect - google.golang.org/api v0.51.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12 // indirect google.golang.org/protobuf v1.27.1 // indirect diff --git a/go.sum b/go.sum index f3f67f19f6676e..b498c4d9d4221d 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,7 @@ cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4g cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/firestore v1.1.0 h1:9x7Bx0A9R5/M9jibeJeZWqjeVEIxYW9fZYqB9a70/bY= cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= diff --git a/pkg/plugin/registry/hub.go b/pkg/plugin/registry/hub.go index a5f26c9ce781b0..e737e062bc1b07 100644 --- a/pkg/plugin/registry/hub.go +++ b/pkg/plugin/registry/hub.go @@ -5,16 +5,20 @@ import ( "fmt" "net/http" "os" + "path" "path/filepath" "runtime" "strings" "time" + "google.golang.org/api/option" + + "cloud.google.com/go/firestore" + "github.com/cloudquery/cloudquery/internal/file" "github.com/cloudquery/cloudquery/internal/logging" "github.com/cloudquery/cloudquery/pkg/config" "github.com/cloudquery/cloudquery/pkg/ui" - "github.com/google/go-github/v35/github" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-version" zerolog "github.com/rs/zerolog/log" @@ -45,26 +49,22 @@ type Hub struct { url string // map of downloaded providers providers map[string]ProviderDetails - - // getLatestRelease is a function that will return latest release from Github repo given organization and repo name. - getLatestRelease LatestReleaseGetter } type Option func(h *Hub) -func WithLatestReleaseGetter(g LatestReleaseGetter) Option { +func WithLatestReleaseGetter(g func()) Option { return func(h *Hub) { - h.getLatestRelease = g + //h.getLatestRelease = g } } func NewRegistryHub(url string, opts ...Option) *Hub { h := &Hub{ - PluginDirectory: filepath.Join(".", ".cq", "providers"), - Logger: logging.NewZHcLog(&zerolog.Logger, ""), - url: url, - providers: make(map[string]ProviderDetails), - getLatestRelease: getLatestRelease, + PluginDirectory: filepath.Join(".", ".cq", "providers"), + Logger: logging.NewZHcLog(&zerolog.Logger, ""), + url: url, + providers: make(map[string]ProviderDetails), } // apply the list of options to hub for _, opt := range opts { @@ -170,11 +170,10 @@ func (h Hub) CheckProviderUpdate(ctx context.Context, requestedProvider *config. ctx, cancel := context.WithTimeout(ctx, versionCheckHTTPTimeout) defer cancel() - release, err := h.getLatestRelease(ctx, organization, ProviderRepoName(providerName)) + latestVersion, err := h.getLatestRelease(ctx, organization, ProviderRepoName(providerName)) if err != nil { return "", err } - latestVersion := release.GetTagName() v, err := version.NewVersion(latestVersion) if err != nil { return "", fmt.Errorf("bad version received: provider %s, version %s", providerName, latestVersion) @@ -193,11 +192,10 @@ func (h Hub) DownloadProvider(ctx context.Context, requestedProvider *config.Req } if providerVersion == "latest" { - release, err := h.getRelease(ctx, organization, providerName, providerVersion) + providerVersion, err = h.getLatestRelease(ctx, organization, providerName) if err != nil { return ProviderDetails{}, err } - providerVersion = release.GetTagName() } p, ok := h.providers[fmt.Sprintf("%s-%s", providerName, providerVersion)] if !ok { @@ -269,26 +267,20 @@ func (h Hub) downloadProvider(ctx context.Context, organization, providerName, p return details, nil } -func (h Hub) getRelease(ctx context.Context, organization, providerName, version string) (*github.RepositoryRelease, error) { - client := github.NewClient(nil) - if version != "latest" { - release, _, err := client.Repositories.GetReleaseByTag(ctx, organization, ProviderRepoName(providerName), version) - return release, err - } - releases, _, err := client.Repositories.ListReleases(ctx, organization, ProviderRepoName(providerName), &github.ListOptions{ - Page: 0, - PerPage: 2, - }) +func (h Hub) getLatestRelease(ctx context.Context, organization, providerName string) (string, error) { + url := fmt.Sprintf(h.url, organization, providerName) + c, err := firestore.NewClient(ctx, "hub-cloudquery", option.WithoutAuthentication(), option.WithHTTPClient(http.DefaultClient)) if err != nil { - return nil, err + return "", err } - if len(releases) == 1 { - return releases[0], nil + docs, err := c.Collection(path.Join(url, "versions")).OrderBy("name", firestore.Desc).Limit(1).Documents(ctx).GetAll() + if err != nil { + return "", err } - if len(releases[0].Assets) < len(releases[1].Assets) { - return releases[1], nil + if len(docs) == 0 { + return "", fmt.Errorf("failed to find provider %s latest version", providerName) } - return releases[0], nil + return "", nil } func (h Hub) verifyRegistered(organization, providerName, version string, noVerify bool) bool { @@ -389,11 +381,3 @@ func parseProviderSource(requestedProvider *config.RequiredProvider) (string, st } return ParseProviderName(requestedSource) } - -type LatestReleaseGetter func(ctx context.Context, owner, repo string) (*github.RepositoryRelease, error) - -func getLatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, error) { - gh := github.NewClient(nil) - r, _, err := gh.Repositories.GetLatestRelease(ctx, owner, repo) - return r, err -} From ad91a80aaf444268358364fade35bab36da8d775 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Wed, 9 Feb 2022 17:56:47 +0000 Subject: [PATCH 3/8] fix typo --- pkg/client/client.go | 4 ++-- pkg/plugin/registry/hub.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 7cc53659e844ee..b07cc1f22c3b99 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -259,9 +259,9 @@ func New(ctx context.Context, options ...Option) (*Client, error) { SkipBuildTables: false, HubProgressUpdater: nil, HistoryCfg: nil, - RegistryURL: registry.CloudQueryRegistryURl, + RegistryURL: registry.CloudQueryRegistryURL, Logger: logging.NewZHcLog(&zerolog.Logger, ""), - Hub: *registry.NewRegistryHub(registry.CloudQueryRegistryURl), + Hub: *registry.NewRegistryHub(registry.CloudQueryRegistryURL), } for _, o := range options { o(c) diff --git a/pkg/plugin/registry/hub.go b/pkg/plugin/registry/hub.go index e737e062bc1b07..be85415a9bb00d 100644 --- a/pkg/plugin/registry/hub.go +++ b/pkg/plugin/registry/hub.go @@ -11,9 +11,8 @@ import ( "strings" "time" - "google.golang.org/api/option" - "cloud.google.com/go/firestore" + "google.golang.org/api/option" "github.com/cloudquery/cloudquery/internal/file" "github.com/cloudquery/cloudquery/internal/logging" @@ -25,7 +24,7 @@ import ( ) const ( - CloudQueryRegistryURl = "https://firestore.googleapis.com/v1/projects/hub-cloudquery/databases/(default)/documents/orgs/%s/providers/%s" + CloudQueryRegistryURL = "https://firestore.googleapis.com/v1/projects/hub-cloudquery/databases/(default)/documents/orgs/%s/providers/%s" // Timeout for http requests related to CloudQuery providers version check. versionCheckHTTPTimeout = time.Second * 10 From 77d4d969a58c365c22a3149ea869fbf131f9a91e Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Wed, 9 Feb 2022 18:12:07 +0000 Subject: [PATCH 4/8] feat: Use firestore for releases --- pkg/plugin/registry/hub.go | 40 +++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/pkg/plugin/registry/hub.go b/pkg/plugin/registry/hub.go index be85415a9bb00d..45fc39204f73ae 100644 --- a/pkg/plugin/registry/hub.go +++ b/pkg/plugin/registry/hub.go @@ -2,18 +2,16 @@ package registry import ( "context" + "encoding/json" "fmt" "net/http" + "net/url" "os" - "path" "path/filepath" "runtime" "strings" "time" - "cloud.google.com/go/firestore" - "google.golang.org/api/option" - "github.com/cloudquery/cloudquery/internal/file" "github.com/cloudquery/cloudquery/internal/logging" "github.com/cloudquery/cloudquery/pkg/config" @@ -267,19 +265,43 @@ func (h Hub) downloadProvider(ctx context.Context, organization, providerName, p } func (h Hub) getLatestRelease(ctx context.Context, organization, providerName string) (string, error) { - url := fmt.Sprintf(h.url, organization, providerName) - c, err := firestore.NewClient(ctx, "hub-cloudquery", option.WithoutAuthentication(), option.WithHTTPClient(http.DefaultClient)) + versions, err := url.Parse(fmt.Sprintf(h.url+"/versions", organization, providerName)) if err != nil { return "", err } - docs, err := c.Collection(path.Join(url, "versions")).OrderBy("name", firestore.Desc).Limit(1).Documents(ctx).GetAll() + qv := versions.Query() + qv.Set("pageSize", "1") + qv.Set("orderBy", "v_major desc, v_minor desc, v_patch desc, published_at desc") + qv.Set("mask.fieldPaths", "tag") + versions.RawQuery = qv.Encode() + + hc := &http.Client{Timeout: 15 * time.Second} + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, versions.String(), nil) + res, err := hc.Do(req) if err != nil { return "", err } - if len(docs) == 0 { + defer res.Body.Close() + if res.StatusCode != http.StatusOK { + return "", fmt.Errorf("unexpected status code %d", res.StatusCode) + } + + var doc struct { + Documents []struct { + Name string `json:"name"` + Fields struct { + Tag string `json:"tag"` + } `json:"fields"` + } `json:"documents"` + } + if err := json.NewDecoder(res.Body).Decode(&doc); err != nil { + return "", err + } + + if len(doc.Documents) == 0 { return "", fmt.Errorf("failed to find provider %s latest version", providerName) } - return "", nil + return doc.Documents[0].Fields.Tag, nil } func (h Hub) verifyRegistered(organization, providerName, version string, noVerify bool) bool { From 8fa5c1c3d0b1c0b692f84b8cb6d8673cecdb79cc Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Wed, 9 Feb 2022 21:42:32 +0000 Subject: [PATCH 5/8] getLatestRelease --- pkg/plugin/registry/hub.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/plugin/registry/hub.go b/pkg/plugin/registry/hub.go index 45fc39204f73ae..b52ebb90aa92e1 100644 --- a/pkg/plugin/registry/hub.go +++ b/pkg/plugin/registry/hub.go @@ -46,13 +46,17 @@ type Hub struct { url string // map of downloaded providers providers map[string]ProviderDetails + // used in tests + getLatestReleaseFn LatestReleaseGetterFunc } type Option func(h *Hub) -func WithLatestReleaseGetter(g func()) Option { +type LatestReleaseGetterFunc func(ctx context.Context, org, provider string) (string, error) + +func WithLatestReleaseGetter(g LatestReleaseGetterFunc) Option { return func(h *Hub) { - //h.getLatestRelease = g + h.getLatestReleaseFn = g } } @@ -265,6 +269,10 @@ func (h Hub) downloadProvider(ctx context.Context, organization, providerName, p } func (h Hub) getLatestRelease(ctx context.Context, organization, providerName string) (string, error) { + if h.getLatestReleaseFn != nil { + return h.getLatestReleaseFn(ctx, organization, providerName) + } + versions, err := url.Parse(fmt.Sprintf(h.url+"/versions", organization, providerName)) if err != nil { return "", err From 6f064c7ebce46e1008a56e8d89ab4a02630f84df Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 10 Feb 2022 12:01:40 +0000 Subject: [PATCH 6/8] Final adjustments --- pkg/plugin/registry/hub.go | 22 ++------ pkg/plugin/registry/hub_test.go | 96 --------------------------------- 2 files changed, 5 insertions(+), 113 deletions(-) delete mode 100644 pkg/plugin/registry/hub_test.go diff --git a/pkg/plugin/registry/hub.go b/pkg/plugin/registry/hub.go index b52ebb90aa92e1..71f2bf0fff530c 100644 --- a/pkg/plugin/registry/hub.go +++ b/pkg/plugin/registry/hub.go @@ -46,20 +46,10 @@ type Hub struct { url string // map of downloaded providers providers map[string]ProviderDetails - // used in tests - getLatestReleaseFn LatestReleaseGetterFunc } type Option func(h *Hub) -type LatestReleaseGetterFunc func(ctx context.Context, org, provider string) (string, error) - -func WithLatestReleaseGetter(g LatestReleaseGetterFunc) Option { - return func(h *Hub) { - h.getLatestReleaseFn = g - } -} - func NewRegistryHub(url string, opts ...Option) *Hub { h := &Hub{ PluginDirectory: filepath.Join(".", ".cq", "providers"), @@ -269,10 +259,6 @@ func (h Hub) downloadProvider(ctx context.Context, organization, providerName, p } func (h Hub) getLatestRelease(ctx context.Context, organization, providerName string) (string, error) { - if h.getLatestReleaseFn != nil { - return h.getLatestReleaseFn(ctx, organization, providerName) - } - versions, err := url.Parse(fmt.Sprintf(h.url+"/versions", organization, providerName)) if err != nil { return "", err @@ -298,7 +284,9 @@ func (h Hub) getLatestRelease(ctx context.Context, organization, providerName st Documents []struct { Name string `json:"name"` Fields struct { - Tag string `json:"tag"` + Tag struct { + Val string `json:"stringValue"` + } `json:"tag"` } `json:"fields"` } `json:"documents"` } @@ -306,10 +294,10 @@ func (h Hub) getLatestRelease(ctx context.Context, organization, providerName st return "", err } - if len(doc.Documents) == 0 { + if len(doc.Documents) == 0 || doc.Documents[0].Fields.Tag.Val == "" { return "", fmt.Errorf("failed to find provider %s latest version", providerName) } - return doc.Documents[0].Fields.Tag, nil + return doc.Documents[0].Fields.Tag.Val, nil } func (h Hub) verifyRegistered(organization, providerName, version string, noVerify bool) bool { diff --git a/pkg/plugin/registry/hub_test.go b/pkg/plugin/registry/hub_test.go deleted file mode 100644 index d18e4d90437f7c..00000000000000 --- a/pkg/plugin/registry/hub_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package registry - -import ( - "context" - "errors" - "testing" - - "github.com/cloudquery/cloudquery/pkg/config" - "github.com/google/go-github/v35/github" -) - -func TestCheckProviderUpdate(t *testing.T) { - type githubResult struct { - version string - err error - } - tests := []struct { - name string - requestedProvider *config.RequiredProvider - github githubResult - want string - wantErr bool - }{ - { - "bad provider name", - &config.RequiredProvider{Name: "very/strange/name"}, - githubResult{}, - "", - true, - }, - { - "bad local provider version", - &config.RequiredProvider{Name: "test", Version: "bad"}, - githubResult{}, - "", - true, - }, - { - "github returns an error", - &config.RequiredProvider{Name: "test", Version: "1.0.0"}, - githubResult{"", errors.New("fake")}, - "", - true, - }, - { - "bad remote provider version", - &config.RequiredProvider{Name: "test", Version: "1.0.0"}, - githubResult{"bad", nil}, - "", - true, - }, - { - "remote version is newer", - &config.RequiredProvider{Name: "test", Version: "1.0.0"}, - githubResult{"1.0.1", nil}, - "1.0.1", - false, - }, - { - "versions are equal", - &config.RequiredProvider{Name: "test", Version: "1.0.0"}, - githubResult{"1.0.0", nil}, - "", - false, - }, - { - "local version is newer", - &config.RequiredProvider{Name: "test", Version: "1.0.1"}, - githubResult{"1.0.0", nil}, - "", - false, - }, - { - "latest version", - &config.RequiredProvider{Name: "test", Version: "latest"}, - githubResult{"1.0.0", nil}, - "", - true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - h := NewRegistryHub("", WithLatestReleaseGetter(func(ctx context.Context, owner, repo string) (*github.RepositoryRelease, error) { - return &github.RepositoryRelease{TagName: &tt.github.version}, tt.github.err - })) - got, err := h.CheckProviderUpdate(context.Background(), tt.requestedProvider) - if (err != nil) != tt.wantErr { - t.Errorf("Hub.CheckProviderUpdate() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("Hub.CheckProviderUpdate() = %v, want %v", got, tt.want) - } - }) - } -} From e825b47ade4366afd98542eb41ecc2632aa6dc39 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 10 Feb 2022 12:07:02 +0000 Subject: [PATCH 7/8] Remove more tests :( --- pkg/client/client_test.go | 100 -------------------------------------- 1 file changed, 100 deletions(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 417f9141ee554a..08a4e2181f310d 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -16,13 +16,10 @@ import ( "github.com/cloudquery/cloudquery/internal/test/provider" "github.com/cloudquery/cloudquery/pkg/config" - "github.com/cloudquery/cloudquery/pkg/plugin/registry" "github.com/cloudquery/cq-provider-sdk/provider/schema" "github.com/cloudquery/cq-provider-sdk/serve" "github.com/fsnotify/fsnotify" "github.com/golang-migrate/migrate/v4" - "github.com/google/go-github/v35/github" - "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-version" "github.com/hashicorp/hcl/v2/hclparse" "github.com/jackc/pgx/v4" @@ -710,100 +707,3 @@ func Test_collectProviderVersions(t *testing.T) { }) } } - -func TestCheckForProviderUpdates(t *testing.T) { - type githubResult struct { - release *github.RepositoryRelease - err error - } - version1 := "1.0.0" - version2 := "2.0.0" - tests := []struct { - name string - providers []*config.RequiredProvider - githubResults []githubResult - want []ProviderUpdateSummary - }{ - { - "empty list of providers", - nil, - nil, - []ProviderUpdateSummary{}, - }, - { - "one provider, github error", - []*config.RequiredProvider{{Name: "test", Version: version1}}, - []githubResult{{nil, errors.New("fake")}}, - []ProviderUpdateSummary{}, - }, - { - "one provider, no update", - []*config.RequiredProvider{{Name: "test", Version: version1}}, - []githubResult{{&github.RepositoryRelease{TagName: &version1}, nil}}, - []ProviderUpdateSummary{}, - }, - { - "latest provider, no update", - []*config.RequiredProvider{{Name: "test", Version: "latest"}}, - []githubResult{{&github.RepositoryRelease{TagName: &version1}, nil}}, - []ProviderUpdateSummary{}, - }, - { - "two providers, one update", - []*config.RequiredProvider{ - {Name: "test", Version: version1}, - {Name: "other", Version: version1}, - }, - []githubResult{ - {&github.RepositoryRelease{TagName: &version1}, nil}, - {&github.RepositoryRelease{TagName: &version2}, nil}, - }, - []ProviderUpdateSummary{ - {Name: "other", Version: version1, LatestVersion: version2}, - }, - }, - { - "three providers, github error, one update", - []*config.RequiredProvider{{Name: "test", Version: version1}, {Name: "other", Version: version1}, {Name: "third", Version: version1}}, - []githubResult{ - {&github.RepositoryRelease{TagName: &version1}, nil}, - {nil, errors.New("fake")}, - {&github.RepositoryRelease{TagName: &version2}, nil}, - }, - []ProviderUpdateSummary{ - {Name: "third", Version: version1, LatestVersion: version2}, - }, - }, - { - "three providers, three updates", - []*config.RequiredProvider{{Name: "test", Version: version1}, {Name: "other", Version: version1}, {Name: "third", Version: version1}}, - []githubResult{ - {&github.RepositoryRelease{TagName: &version2}, nil}, - {&github.RepositoryRelease{TagName: &version2}, nil}, - {&github.RepositoryRelease{TagName: &version2}, nil}, - }, - []ProviderUpdateSummary{ - {Name: "test", Version: version1, LatestVersion: version2}, - {Name: "other", Version: version1, LatestVersion: version2}, - {Name: "third", Version: version1, LatestVersion: version2}, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ctx := context.Background() - getReleaseCall := 0 - c := Client{ - Providers: tt.providers, - Logger: hclog.Default(), - Hub: *registry.NewRegistryHub("", registry.WithLatestReleaseGetter(func(ctx context.Context, owner, repo string) (*github.RepositoryRelease, error) { - r := tt.githubResults[getReleaseCall] - getReleaseCall++ - return r.release, r.err - })), - } - got := c.CheckForProviderUpdates(ctx) - assert.Equal(t, tt.want, got) - }) - } -} From 902790f18a224a62a96da6045976c3d341a27e0a Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 10 Feb 2022 12:07:32 +0000 Subject: [PATCH 8/8] tidy --- go.mod | 3 +-- go.sum | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9426a60503023b..ad4d52e9c04ab3 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,6 @@ require ( ) require ( - cloud.google.com/go/firestore v1.1.0 github.com/ProtonMail/go-crypto v0.0.0-20211221144345-a4f6767435ab github.com/aws/aws-sdk-go v1.42.1 github.com/creasty/defaults v1.5.2 @@ -56,7 +55,6 @@ require ( go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.2.0 go.opentelemetry.io/otel/sdk v1.2.0 go.opentelemetry.io/otel/trace v1.2.0 - google.golang.org/api v0.51.0 google.golang.org/grpc v1.42.0 ) @@ -134,6 +132,7 @@ require ( golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.5 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + google.golang.org/api v0.51.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12 // indirect google.golang.org/protobuf v1.27.1 // indirect diff --git a/go.sum b/go.sum index b498c4d9d4221d..f3f67f19f6676e 100644 --- a/go.sum +++ b/go.sum @@ -34,7 +34,6 @@ cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4g cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/firestore v1.1.0 h1:9x7Bx0A9R5/M9jibeJeZWqjeVEIxYW9fZYqB9a70/bY= cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=