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

integration test skeleton

parent 0d742e8b
Branches
Tags
2 merge requests!110Integration test,!90Develop
Pipeline #66368 passed with warnings
...@@ -43,16 +43,26 @@ deploy:latest: ...@@ -43,16 +43,26 @@ deploy:latest:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
<<: *deploy <<: *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: deploy:merge-request:master:
variables: variables:
TAG: $CI_REGISTRY_IMAGE:mr-master TAG: $CI_REGISTRY_IMAGE:mr-master
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
<<: *deploy <<: *deploy-mr
deploy:merge-mr:develop: deploy:merge-mr:develop:
variables: variables:
TAG: $CI_REGISTRY_IMAGE:mr-develop TAG: $CI_REGISTRY_IMAGE:mr-develop
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop' - 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 image: golang:1.14
stage: test stage: test
rules: rules:
...@@ -18,6 +18,6 @@ unit-test: ...@@ -18,6 +18,6 @@ unit-test:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
script: 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: after_script:
- go tool cover -func=coverage.out - go tool cover -func=coverage.out
\ No newline at end of file
...@@ -25,7 +25,10 @@ func main() { ...@@ -25,7 +25,10 @@ func main() {
Uuid: uuid.New(), 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 { if err := pnd.AddDevice(&device); err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -23,7 +23,7 @@ func main() { ...@@ -23,7 +23,7 @@ func main() {
Uuid: uuid.New(), Uuid: uuid.New(),
}, },
} }
pnd, err := nucleus.NewPND("openconfig", "test description", sbi) pnd, err := nucleus.NewPND("openconfig", "test description", uuid.New(), sbi)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
func main() { func main() {
_, debug := os.LookupEnv("GOSDN_DEBUG") _, debug := os.LookupEnv("GOSDN_DEBUG")
_, integrationTest := os.LookupEnv("GOSDN_TEST")
if debug { if debug {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
} }
...@@ -17,9 +16,5 @@ func main() { ...@@ -17,9 +16,5 @@ func main() {
IsRunningChannel := make(chan bool) IsRunningChannel := make(chan bool)
// hand off to cmd for further processing // hand off to cmd for further processing
if !integrationTest {
nucleus.StartAndRun(IsRunningChannel) 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 { ...@@ -34,20 +34,7 @@ type pndImplementation struct {
} }
// NewPND creates a Principle Network Domain // NewPND creates a Principle Network Domain
func NewPND(name, description string, sbi SouthboundInterface) (PrincipalNetworkDomain, error) { func NewPND(name, description string, id uuid.UUID, 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) {
pnd := &pndImplementation{ pnd := &pndImplementation{
name: name, name: name,
description: description, description: description,
......
...@@ -81,6 +81,7 @@ func TestNewPND(t *testing.T) { ...@@ -81,6 +81,7 @@ func TestNewPND(t *testing.T) {
name string name string
description string description string
sbi SouthboundInterface sbi SouthboundInterface
pid uuid.UUID
} }
tests := []struct { tests := []struct {
name string name string
...@@ -94,6 +95,7 @@ func TestNewPND(t *testing.T) { ...@@ -94,6 +95,7 @@ func TestNewPND(t *testing.T) {
name: "default", name: "default",
description: "default test pnd", description: "default test pnd",
sbi: &OpenConfig{id: defaultSbiId}, sbi: &OpenConfig{id: defaultSbiId},
pid: defaultPndId,
}, },
want: &pnd, want: &pnd,
wantErr: false, wantErr: false,
...@@ -101,7 +103,7 @@ func TestNewPND(t *testing.T) { ...@@ -101,7 +103,7 @@ func TestNewPND(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) {
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 { if (err != nil) != tt.wantErr {
t.Errorf("NewPND() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("NewPND() error = %v, wantErr %v", err, tt.wantErr)
return return
...@@ -113,49 +115,6 @@ func TestNewPND(t *testing.T) { ...@@ -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) { func Test_destroy(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment