Skip to content
Snippets Groups Projects

Resolve "Nil pointer dereference in integration test"

Merged Ghost User requested to merge 122-nil-pointer-dereference-in-integration-test into develop
Files
24
package integration
package api
import (
import (
 
"fmt"
 
"os"
 
"testing"
 
tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/api"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
"fmt"
guuid "github.com/google/uuid"
guuid "github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/spf13/viper"
pb "google.golang.org/protobuf/proto"
pb "google.golang.org/protobuf/proto"
"os"
"testing"
)
)
const unreachable = "203.0.113.10:6030"
const unreachable = "203.0.113.10:6030"
@@ -20,10 +20,11 @@ const testPath = "/system/config/hostname"
@@ -20,10 +20,11 @@ const testPath = "/system/config/hostname"
var testIP = "141.100.70.171"
var testIP = "141.100.70.171"
var testPort = "6030"
var testPort = "6030"
var testAddress = testIP + ":" + testPort
var testAddress = testIP + ":" + testPort
var testAPIEndpoint = "http://gosdn-latest.apps.ocp.fbi.h-da.de/api"
var testAPIEndpoint = "gosdn-latest.apps.ocp.fbi.h-da.de"
var testUsername = "admin"
var testUsername = "admin"
var testPassword = "arista"
var testPassword = "arista"
var opt *tpb.TransportOption
var opt *tpb.TransportOption
 
var gnmiMessages map[string]pb.Message
func TestMain(m *testing.M) {
func TestMain(m *testing.M) {
testSetupIntegration()
testSetupIntegration()
@@ -31,6 +32,11 @@ func TestMain(m *testing.M) {
@@ -31,6 +32,11 @@ func TestMain(m *testing.M) {
}
}
func testSetupIntegration() {
func testSetupIntegration() {
 
viper.SetConfigFile(".k8s.toml")
 
if err := viper.ReadInConfig(); err != nil {
 
log.Error(err)
 
}
 
if os.Getenv("GOSDN_LOG") == "nolog" {
if os.Getenv("GOSDN_LOG") == "nolog" {
log.SetLevel(log.PanicLevel)
log.SetLevel(log.PanicLevel)
}
}
@@ -91,7 +97,9 @@ func testSetupIntegration() {
@@ -91,7 +97,9 @@ func testSetupIntegration() {
}
}
}
}
func TestCmdIntegration(t *testing.T) {
func TestApiIntegration(t *testing.T) {
 
// TDOO: Remove once openshift grpc support is available
 
t.Skip("skipped due to openshift limitations")
if testing.Short() {
if testing.Short() {
t.Skip("skipping integration test")
t.Skip("skipping integration test")
}
}
@@ -107,7 +115,7 @@ func TestCmdIntegration(t *testing.T) {
@@ -107,7 +115,7 @@ func TestCmdIntegration(t *testing.T) {
for _, tt := range tests {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
defer viper.Reset()
defer viper.Reset()
if err := api.Init(testAPIEndpoint); (err != nil) != tt.wantErr {
if err := Init(testAPIEndpoint); (err != nil) != tt.wantErr {
switch err.(type) {
switch err.(type) {
case viper.ConfigFileNotFoundError:
case viper.ConfigFileNotFoundError:
default:
default:
@@ -118,7 +126,7 @@ func TestCmdIntegration(t *testing.T) {
@@ -118,7 +126,7 @@ func TestCmdIntegration(t *testing.T) {
cliPnd := viper.GetString("CLI_PND")
cliPnd := viper.GetString("CLI_PND")
cliSbi := viper.GetString("CLI_SBI")
cliSbi := viper.GetString("CLI_SBI")
if _, err := api.AddDevice(
if _, err := AddDevice(
testAPIEndpoint,
testAPIEndpoint,
testUsername,
testUsername,
testPassword,
testPassword,
@@ -132,7 +140,7 @@ func TestCmdIntegration(t *testing.T) {
@@ -132,7 +140,7 @@ func TestCmdIntegration(t *testing.T) {
}
}
did := viper.GetString("LAST_DEVICE_UUID")
did := viper.GetString("LAST_DEVICE_UUID")
_, err := api.GetDevice(
_, err := GetDevice(
testAPIEndpoint,
testAPIEndpoint,
cliPnd,
cliPnd,
testPath,
testPath,
@@ -143,7 +151,7 @@ func TestCmdIntegration(t *testing.T) {
@@ -143,7 +151,7 @@ func TestCmdIntegration(t *testing.T) {
return
return
}
}
_, err = api.GetDevice(
_, err = GetDevice(
testAPIEndpoint,
testAPIEndpoint,
cliPnd,
cliPnd,
"",
"",
@@ -155,7 +163,7 @@ func TestCmdIntegration(t *testing.T) {
@@ -155,7 +163,7 @@ func TestCmdIntegration(t *testing.T) {
}
}
hostname := guuid.New().String()
hostname := guuid.New().String()
_, err = api.Update(
_, err = Update(
testAPIEndpoint,
testAPIEndpoint,
did,
did,
cliPnd,
cliPnd,
@@ -167,10 +175,10 @@ func TestCmdIntegration(t *testing.T) {
@@ -167,10 +175,10 @@ func TestCmdIntegration(t *testing.T) {
return
return
}
}
resp, err := api.GetDevice(testAddress, testUsername, testPassword, testPath)
resp, err := GetDevice(testAddress, testUsername, testPassword, testPath)
if err != nil {
if err != nil {
if !tt.wantErr {
if !tt.wantErr {
t.Errorf("api.Get() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr)
}
}
return
return
}
}
Loading