Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic tests for increasing code-coverage #372

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions admiral/pkg/apis/admiral/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,3 @@ func Logger(inner http.Handler, name string) http.Handler {
)
})
}

func Auth(inner http.Handler, name string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

log.Printf(
"Auth Logger for endpoint %s", name,
)
//TODO implement authnz

inner.ServeHTTP(w, r)

})
}
31 changes: 31 additions & 0 deletions admiral/pkg/clusters/sidecar_handler_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
package clusters

import (
"context"
"github.com/stretchr/testify/assert"
"istio.io/client-go/pkg/apis/networking/v1alpha3"
"testing"
)

func TestSidecarHandler_Added(t *testing.T) {
var dh SidecarHandler
var ctx context.Context
var obj *v1alpha3.Sidecar
err := dh.Added(ctx, obj)
assert.Nil(t, err)
}

func TestSidecarHandler_Updated(t *testing.T) {
var dh SidecarHandler
var ctx context.Context
var obj *v1alpha3.Sidecar
err := dh.Updated(ctx, obj)
assert.Nil(t, err)
}

func TestSidecarHandler_Deleted(t *testing.T) {
var dh SidecarHandler
var ctx context.Context
var obj *v1alpha3.Sidecar
err := dh.Deleted(ctx, obj)
assert.Nil(t, err)
}
35 changes: 35 additions & 0 deletions admiral/pkg/clusters/types_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package clusters

import (
"github.com/stretchr/testify/assert"
"sync"
"testing"
"time"

"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -42,3 +44,36 @@ func setupForTypeTests() {
common.InitializeConfig(admiralParamsForTypesTests())
})
}

func TestRangeRemoteControllers(t *testing.T) {
setupForTypeTests()

rr := &RemoteRegistry{
Mutex: sync.Mutex{},
remoteControllers: map[string]*RemoteController{"test": &RemoteController{}},
}

counter := 0
// testFunc is a function that tests the RemoteController
testFunc := func(k string, v *RemoteController) {
counter = counter + 1
}

// TestRangeRemoteControllers is a table-driven test for RangeRemoteControllers
tests := []struct {
name string
expected int
}{
{
name: "TestRangeRemoteControllers",
expected: 1,
},
}
for _, tt := range tests {
counter = 0
t.Run(tt.name, func(t *testing.T) {
rr.RangeRemoteControllers(testFunc)
assert.Equal(t, tt.expected, counter)
})
}
}
25 changes: 25 additions & 0 deletions admiral/pkg/controller/admiral/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package admiral

import (
"context"
"github.com/istio-ecosystem/admiral/admiral/pkg/client/loader"
"testing"
"time"

Expand Down Expand Up @@ -172,3 +173,27 @@ func TestConfigMapController_PutConfigMap(t *testing.T) {
}

}

func TestNewConfigMapController(t *testing.T) {
clientLoader := &loader.FakeClientLoader{}
seIPPrefix := "prefix"
controller, err := NewConfigMapController(seIPPrefix, clientLoader)
if err != nil {
t.Errorf("No error expected. Err: %v", err)
}

if controller.ServiceEntryIPPrefix != seIPPrefix {
t.Errorf("Expected %v but got %v", seIPPrefix, controller.ServiceEntryIPPrefix)
}
}

func TestConfigMapController_GetIPPrefixForServiceEntries(t *testing.T) {
seIPPrefix := "prefix"
controller := ConfigMapController{
ServiceEntryIPPrefix: seIPPrefix,
}

if controller.GetIPPrefixForServiceEntries() != seIPPrefix {
t.Errorf("Expected %v but got %v", seIPPrefix, controller.GetIPPrefixForServiceEntries())
}
}
Loading