Skip to content

Commit

Permalink
fix: update dependencies
Browse files Browse the repository at this point in the history
this mainly upgrades github.com/ninech/apis and loki because of some
broken dependencies. The loki upgrade required some changes to the fake
client since the interface changed slightly. The other test changes are
due to a behaviour changes of the k8s fake client.
  • Loading branch information
ctrox committed Jan 10, 2024
1 parent 4ad6bea commit 7a1969d
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 1,236 deletions.
5 changes: 0 additions & 5 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ninech/apis"
"github.com/ninech/nctl/api/log"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -56,12 +55,8 @@ func New(ctx context.Context, apiClusterContext, project string, opts ...ClientO
return nil, err
}

mapper := apis.StaticRESTMapper(scheme)
mapper.Add(corev1.SchemeGroupVersion.WithKind("Secret"), meta.RESTScopeNamespace)

c, err := runtimeclient.NewWithWatch(client.Config, runtimeclient.Options{
Scheme: scheme,
Mapper: mapper,
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion api/log/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestClient(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%s %s\n", expectedTime.Local().Format(time.RFC3339), expectedLine), buf.String())
buf.Reset()

if err := c.TailQuery(ctx, 0, out, Query{Limit: 10}); err != nil {
if err := c.TailQuery(ctx, 0, out, Query{QueryString: "{app=\"test\"}", Limit: 10}); err != nil {
t.Fatal(err)
}
assert.Equal(t, fmt.Sprintf("%s %s\n", expectedTime.Local().Format(time.RFC3339), expectedLine), buf.String())
Expand Down
31 changes: 26 additions & 5 deletions api/log/fake.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package log

import (
"errors"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -9,10 +10,12 @@ import (
"time"

"github.com/gorilla/websocket"
"github.com/grafana/loki/pkg/logcli/volume"
"github.com/grafana/loki/pkg/loghttp"
legacy "github.com/grafana/loki/pkg/loghttp/legacy"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/httpreq"
"github.com/grafana/loki/pkg/util/marshal"
)

Expand All @@ -32,6 +35,11 @@ func NewFake(t *testing.T, expectedTime time.Time, expectedLines ...string) *fak
func lokiTailHandler(t *testing.T, timestamp time.Time, lines []string) http.HandlerFunc {
upgrader := websocket.Upgrader{}
return func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
t.Error(err)
return
}

req, err := loghttp.ParseTailQuery(r)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -64,7 +72,8 @@ func lokiTailHandler(t *testing.T, timestamp time.Time, lines []string) http.Han
},
}

if err := marshal.WriteTailResponseJSON(resp, c); err != nil {
connWriter := marshal.NewWebsocketJSONWriter(c)
if err := marshal.WriteTailResponseJSON(resp, connWriter, httpreq.ExtractEncodingFlags(r)); err != nil {
t.Error(err)
return
}
Expand Down Expand Up @@ -125,21 +134,33 @@ func (f fake) LiveTailQueryConn(queryStr string, delayFor time.Duration, limit i
}

func (f fake) ListLabelNames(quiet bool, start, end time.Time) (*loghttp.LabelResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) ListLabelValues(name string, quiet bool, start, end time.Time) (*loghttp.LabelResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) Series(matchers []string, start, end time.Time, quiet bool) (*loghttp.SeriesResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) Query(queryStr string, limit int, time time.Time, direction logproto.Direction, quiet bool) (*loghttp.QueryResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) GetOrgID() string {
return "fake"
}

func (f fake) GetStats(queryStr string, start, end time.Time, quiet bool) (*logproto.IndexStatsResponse, error) {
return nil, errors.New("not implemented")
}

func (f fake) GetVolume(query *volume.Query) (*loghttp.QueryResponse, error) {
return nil, errors.New("not implemented")
}

func (f fake) GetVolumeRange(query *volume.Query) (*loghttp.QueryResponse, error) {
return nil, errors.New("not implemented")
}
12 changes: 6 additions & 6 deletions create/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestApplicationWait(t *testing.T) {
app.Status.AtProvider.Hosts = []apps.VerificationStatus{{Name: "host.example.org"}}
app.Status.AtProvider.CNAMETarget = "some.target.example.org"
app.Status.AtProvider.BasicAuthSecret = &meta.LocalReference{Name: basicAuth.Name}
if err := apiClient.Status().Update(ctx, app); err != nil {
if err := apiClient.Update(ctx, app); err != nil {
errors <- err
}

Expand All @@ -428,12 +428,12 @@ func TestApplicationWait(t *testing.T) {
}

build.Status.AtProvider.BuildStatus = buildStatusRunning
if err := apiClient.Status().Update(ctx, build); err != nil {
if err := apiClient.Update(ctx, build); err != nil {
errors <- err
}

build.Status.AtProvider.BuildStatus = buildStatusSuccess
if err := apiClient.Status().Update(ctx, build); err != nil {
if err := apiClient.Update(ctx, build); err != nil {
errors <- err
}

Expand All @@ -442,7 +442,7 @@ func TestApplicationWait(t *testing.T) {
}

release.Status.AtProvider.ReleaseStatus = releaseStatusAvailable
if err := apiClient.Status().Update(ctx, release); err != nil {
if err := apiClient.Update(ctx, release); err != nil {
errors <- err
}
}
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestApplicationBuildFail(t *testing.T) {
}

build.Status.AtProvider.BuildStatus = buildStatusError
if err := client.Status().Update(ctx, build); err != nil {
if err := client.Update(ctx, build); err != nil {
errors <- err
}
}
Expand Down Expand Up @@ -553,5 +553,5 @@ func setResourceCondition(ctx context.Context, apiClient *api.Client, mg resourc
}

mg.SetConditions(condition)
return apiClient.Status().Update(ctx, mg)
return apiClient.Update(ctx, mg)
}
2 changes: 1 addition & 1 deletion create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestCreate(t *testing.T) {
}

asa.SetConditions(runtimev1.Available())
if err := apiClient.Status().Update(ctx, asa); err != nil {
if err := apiClient.Update(ctx, asa); err != nil {
errChan <- err
}
}
Expand Down
2 changes: 1 addition & 1 deletion get/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dev
projects: test.Projects(organization, "dev", "staging"),
name: "dev",
outputFormat: yamlOut,
output: "kind: Project\napiVersion: management.nine.ch/v1alpha1\nmetadata:\n name: dev\n namespace: evilcorp\nspec: {}\n",
output: "kind: Project\napiVersion: management.nine.ch/v1alpha1\nmetadata:\n name: dev\n namespace: evilcorp\nspec:\n isNonProduction: false\n",
},
} {
t.Run(name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 7a1969d

Please sign in to comment.