Skip to content
Snippets Groups Projects
Commit 8b64018f authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

integration test skeleton

parent 0d742e8b
No related branches found
No related tags found
2 merge requests!110Integration test,!90Develop
Pipeline #66368 passed with warnings
......@@ -43,16 +43,26 @@ deploy:latest:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
<<: *deploy
.deploy:mr: &deploy-mr
stage: deploy
needs: ["build:docker"]
tags:
- baremetal
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker tag $DOCKER_IMAGE_SHA $TAG
- docker push $TAG
deploy:merge-request:master:
variables:
TAG: $CI_REGISTRY_IMAGE:mr-master
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
<<: *deploy
<<: *deploy-mr
deploy:merge-mr:develop:
variables:
TAG: $CI_REGISTRY_IMAGE:mr-develop
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop'
<<: *deploy
<<: *deploy-mr
unit-test-master:
integration-test:
image: golang:1.14
stage: test
rules:
......@@ -18,6 +18,6 @@ unit-test:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
script:
- go test -race $(go list ./... | grep -v /forks/ | grep -v /api/ | grep -v /mocks ) -v -coverprofile=coverage.out
- go test -short -race $(go list ./... | grep -v /forks/ | grep -v /api/ | grep -v /mocks ) -v -coverprofile=coverage.out
after_script:
- go tool cover -func=coverage.out
\ No newline at end of file
......@@ -25,7 +25,10 @@ func main() {
Uuid: uuid.New(),
},
}
pnd := nucleus.NewPND("openconfig", "a simple openconfig PND", sbi)
pnd, err := nucleus.NewPND("openconfig", "a simple openconfig PND", uuid.New(), sbi)
if err != nil {
log.Fatal(err)
}
if err := pnd.AddDevice(&device); err != nil {
log.Fatal(err)
}
......
......@@ -23,7 +23,7 @@ func main() {
Uuid: uuid.New(),
},
}
pnd, err := nucleus.NewPND("openconfig", "test description", sbi)
pnd, err := nucleus.NewPND("openconfig", "test description", uuid.New(), sbi)
if err != nil {
log.Fatal(err)
}
......
......@@ -8,7 +8,6 @@ import (
func main() {
_, debug := os.LookupEnv("GOSDN_DEBUG")
_, integrationTest := os.LookupEnv("GOSDN_TEST")
if debug {
log.SetLevel(log.DebugLevel)
}
......@@ -17,9 +16,5 @@ func main() {
IsRunningChannel := make(chan bool)
// hand off to cmd for further processing
if !integrationTest {
nucleus.StartAndRun(IsRunningChannel)
} else {
nucleus.IntegrationTests()
}
}
package nucleus
import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"context"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
"time"
)
func IntegrationTests() {
sbi := &OpenConfig{}
device := &Device{
GoStruct: sbi.Schema().Root,
SBI: sbi,
Config: DeviceConfig{
Uuid: uuid.New(),
},
}
pnd, err := NewPND("openconfig", "test description", sbi)
if err != nil {
log.Fatal(err)
}
if err := pnd.AddDevice(device); err != nil {
log.Fatal(err)
}
cfg := &gnmi.Config{
Addr: "172.100.100.20:6030",
Username: "admin",
Password: "admin",
Encoding: gpb.Encoding_JSON_IETF,
}
transport, err := NewGnmiTransport(cfg)
if err != nil {
log.Fatal(err)
}
transport.SetNode = sbi.SetNode()
device.Transport = transport
var resp interface{}
for i := 0; i < 10; i++ {
deadline := time.Now().Add(10 * time.Second)
ctx, cancel := context.WithDeadline(context.Background(), deadline)
resp, err = transport.Capabilities(ctx)
cancel()
if err != nil {
if i < 9 {
log.Error(err)
log.Infof("retrying. %v of 10", i+1)
} else {
log.Fatal(err)
}
}
}
log.Fatal(resp)
}
package nucleus
import "testing"
func TestGnmi_SetIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
}
func TestGnmi_GetIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
}
func TestGnmi_SubscribeIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
}
func TestGnmi_CapabilitiesIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
}
func TestPndImplementation_RequestAllIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
}
func TestPndImplementation_RequestIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
}
\ No newline at end of file
......@@ -34,20 +34,7 @@ type pndImplementation struct {
}
// NewPND creates a Principle Network Domain
func NewPND(name, description string, sbi SouthboundInterface) (PrincipalNetworkDomain, error) {
pnd := &pndImplementation{
name: name,
description: description,
sbic: sbiStore{store{}},
devices: deviceStore{store{}},
}
if err := pnd.sbic.add(sbi); err != nil {
return nil, &ErrAlreadyExists{item: sbi}
}
return pnd, nil
}
func NewPNDwithId(name, description string, id uuid.UUID, sbi SouthboundInterface) (PrincipalNetworkDomain, error) {
func NewPND(name, description string, id uuid.UUID, sbi SouthboundInterface) (PrincipalNetworkDomain, error) {
pnd := &pndImplementation{
name: name,
description: description,
......
......@@ -81,6 +81,7 @@ func TestNewPND(t *testing.T) {
name string
description string
sbi SouthboundInterface
pid uuid.UUID
}
tests := []struct {
name string
......@@ -94,6 +95,7 @@ func TestNewPND(t *testing.T) {
name: "default",
description: "default test pnd",
sbi: &OpenConfig{id: defaultSbiId},
pid: defaultPndId,
},
want: &pnd,
wantErr: false,
......@@ -101,7 +103,7 @@ func TestNewPND(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewPND(tt.args.name, tt.args.description, tt.args.sbi)
got, err := NewPND(tt.args.name, tt.args.description, tt.args.pid, tt.args.sbi)
if (err != nil) != tt.wantErr {
t.Errorf("NewPND() error = %v, wantErr %v", err, tt.wantErr)
return
......@@ -113,49 +115,6 @@ func TestNewPND(t *testing.T) {
}
}
func TestNewPNDwithId(t *testing.T) {
pnd := newPndWithId()
if err := pnd.addSbi(&OpenConfig{id: defaultSbiId}); err != nil {
t.Error(err)
}
type args struct {
name string
description string
id uuid.UUID
sbi SouthboundInterface
}
tests := []struct {
name string
args args
want PrincipalNetworkDomain
wantErr bool
}{
{
name: "default",
args: args{
name: "default",
description: "default test pnd",
id: defaultPndId,
sbi: &OpenConfig{id: defaultSbiId},
},
want: &pnd,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewPNDwithId(tt.args.name, tt.args.description, tt.args.id, tt.args.sbi)
if (err != nil) != tt.wantErr {
t.Errorf("NewPNDwithId() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewPNDwithId() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_destroy(t *testing.T) {
tests := []struct {
name string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment