Skip to content

Commit

Permalink
fix: lint errors (#923)
Browse files Browse the repository at this point in the history
Signed-off-by: amitamrutiya2210 <amitamrutiya2210@gmail.com>
  • Loading branch information
amitamrutiya committed Feb 7, 2024
1 parent d97dea2 commit 3415031
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 36 deletions.
6 changes: 3 additions & 3 deletions cmd/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
)

var (
backend string
backend string
backendType string
)

// generateCmd represents the auth command
Expand All @@ -34,14 +35,13 @@ var GenerateCmd = &cobra.Command{
Long: `Opens your browser to generate a key for your chosen backend.`,
Run: func(cmd *cobra.Command, args []string) {

backendType := viper.GetString("backend_type")
backendType = viper.GetString("backend_type")
if backendType == "" {
// Set the default backend
backend = "openai"
}
// override the default backend if a flag is provided
if backend != "" {
//nolint:all
backendType = backend
}
fmt.Println("")
Expand Down
7 changes: 6 additions & 1 deletion cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ var ServeCmd = &cobra.Command{
color.Red("failed to create logger: %v", err)
os.Exit(1)
}
defer logger.Sync()
defer func() {
if err := logger.Sync(); err != nil {
color.Red("failed to sync logger: %v", err)
os.Exit(1)
}
}()

server := k8sgptserver.Config{
Backend: aiProvider.Name,
Expand Down
34 changes: 25 additions & 9 deletions pkg/analyzer/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ func TestGatewayAnalyzer(t *testing.T) {
Gateway := BuildGateway(ClassName, AcceptedStatus)
// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
//nolint:all
gtwapi.Install(scheme)
//nolint:all
apiextensionsv1.AddToScheme(scheme)

err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&Gateway,
&GatewayClass,
Expand Down Expand Up @@ -90,9 +95,14 @@ func TestMissingClassGatewayAnalyzer(t *testing.T) {

// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
//nolint:all
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&Gateway,
}
Expand Down Expand Up @@ -124,8 +134,14 @@ func TestStatusGatewayAnalyzer(t *testing.T) {

// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&Gateway,
&GatewayClass,
Expand Down
5 changes: 4 additions & 1 deletion pkg/analyzer/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func (GatewayClassAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error)

gcList := &gtwapi.GatewayClassList{}
client := a.Client.CtrlClient
gtwapi.AddToScheme(client.Scheme())
err := gtwapi.AddToScheme(client.Scheme())
if err != nil {
return nil, err
}
if err := client.List(a.Context, gcList, &ctrl.ListOptions{}); err != nil {
return nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/analyzer/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ func TestGatewayClassAnalyzer(t *testing.T) {
GatewayClass.Status.Conditions = []metav1.Condition{BadCondition}
// Create a GatewayClassAnalyzer instance with the fake client
scheme := scheme.Scheme
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}

fakeClient := fakeclient.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(GatewayClass).Build()

Expand Down
5 changes: 4 additions & 1 deletion pkg/analyzer/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ func (HTTPRouteAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {
gtw := &gtwapi.Gateway{}
service := &corev1.Service{}
client := a.Client.CtrlClient
gtwapi.AddToScheme(client.Scheme())
err := gtwapi.AddToScheme(client.Scheme())
if err != nil {
return nil, err
}
if err := client.List(a.Context, routeList, &ctrl.ListOptions{}); err != nil {
return nil, err
}
Expand Down
50 changes: 40 additions & 10 deletions pkg/analyzer/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ func TestGWMissiningHTTRouteAnalyzer(t *testing.T) {
HTTPRoute := BuildHTTPRoute(backendName, gtwName, gtwNamespace, &svcPort, httpRouteNamespace)
// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&HTTPRoute,
}
Expand Down Expand Up @@ -156,8 +162,14 @@ func TestGWConfigSameHTTRouteAnalyzer(t *testing.T) {
Gateway := BuildRouteGateway("differentnamespace", "gatewayname", "Same")
// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&HTTPRoute,
&Gateway,
Expand Down Expand Up @@ -207,8 +219,14 @@ func TestGWConfigSelectorHTTRouteAnalyzer(t *testing.T) {
Gateway := BuildRouteGateway("default", "gatewayname", "Selector")
// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&HTTPRoute,
&Gateway,
Expand Down Expand Up @@ -259,8 +277,14 @@ func TestSvcMissingHTTRouteAnalyzer(t *testing.T) {
Gateway := BuildRouteGateway("default", "gatewayname", "Same")
// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&HTTPRoute,
&Gateway,
Expand Down Expand Up @@ -332,8 +356,14 @@ func TestSvcDifferentPortHTTRouteAnalyzer(t *testing.T) {
Gateway := BuildRouteGateway("default", "gatewayname", "Same")
// Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme
gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme)
err := gtwapi.Install(scheme)
if err != nil {
t.Error(err)
}
err = apiextensionsv1.AddToScheme(scheme)
if err != nil {
t.Error(err)
}
objects := []runtime.Object{
&HTTPRoute,
&Gateway,
Expand Down
4 changes: 2 additions & 2 deletions pkg/integration/prometheus/config_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ func findPrometheusConfigPath(ctx context.Context, client kubernetes.Interface,
// references the ConfigMap or Secret volume mount.
// Fallback to the prometheus container if that's not found.
if strings.HasPrefix(arg, prometheusConfigFlag) {
path = strings.TrimLeft(arg, prometheusConfigFlag)
path = strings.TrimPrefix(arg, prometheusConfigFlag)
}
if strings.HasPrefix(arg, configReloaderConfigFlag) {
path = strings.TrimLeft(arg, configReloaderConfigFlag)
path = strings.TrimPrefix(arg, configReloaderConfigFlag)
}
}
if container.Name == configReloaderContainerName {
Expand Down
6 changes: 6 additions & 0 deletions pkg/server/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func (h *handler) syncIntegration(ctx context.Context,
activeFilters = coreFilters
}
var err error = status.Error(codes.OK, "")
if err != nil {
fmt.Println(err)
}
deactivateFunc := func(integrationRef integration.IIntegration) error {
namespace, err := integrationRef.GetNamespace()
if err != nil {
Expand Down Expand Up @@ -125,6 +128,9 @@ func (*handler) deactivateAllIntegrations(integrationProvider *integration.Integ
b, _ := integrationProvider.IsActivate(i)
if b {
in, err := integrationProvider.Get(i)
if err != nil {
return err
}
namespace, err := in.GetNamespace()
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Config struct {
listener net.Listener
}

//nolint:unused
type Health struct {
Status string `json:"status"`
Success int `json:"success"`
Expand Down
7 changes: 1 addition & 6 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"os"
"sync"
"testing"

"github.com/fatih/color"
Expand All @@ -25,19 +24,15 @@ func TestServerInit(t *testing.T) {
Token: "none",
Logger: logger,
}
var wg sync.WaitGroup

go func() {
wg.Add(1)
err := server_config.Serve()
if err != nil {
assert.Fail(t, "serve: %s", err.Error())
}
server_config.Shutdown()
err = server_config.Shutdown()
if err != nil {
assert.Fail(t, "shutdown: %s", err.Error())
}
wg.Done()
}()
wg.Wait()
}

0 comments on commit 3415031

Please sign in to comment.