From 8b64018f8f376e256cb1df24411bd1d1c3d24b8a Mon Sep 17 00:00:00 2001 From: Manuel Kieweg <mail@manuelkieweg.de> Date: Wed, 3 Mar 2021 19:30:57 +0000 Subject: [PATCH] integration test skeleton --- build/ci/.build-container.yml | 14 +++++- build/ci/.test.yml | 4 +- cmd/gnmi-telemetry/telemetry.go | 5 ++- cmd/gnmi/gnmi.go | 2 +- cmd/gosdn/main.go | 5 --- nucleus/integration.go | 59 -------------------------- nucleus/integration_test.go | 39 +++++++++++++++++ nucleus/principalNetworkDomain.go | 15 +------ nucleus/principalNetworkDomain_test.go | 47 ++------------------ 9 files changed, 62 insertions(+), 128 deletions(-) delete mode 100644 nucleus/integration.go create mode 100644 nucleus/integration_test.go diff --git a/build/ci/.build-container.yml b/build/ci/.build-container.yml index 771db4345..3d1d3576d 100644 --- a/build/ci/.build-container.yml +++ b/build/ci/.build-container.yml @@ -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 diff --git a/build/ci/.test.yml b/build/ci/.test.yml index f6114fcf3..587bc1d39 100644 --- a/build/ci/.test.yml +++ b/build/ci/.test.yml @@ -1,4 +1,4 @@ -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 diff --git a/cmd/gnmi-telemetry/telemetry.go b/cmd/gnmi-telemetry/telemetry.go index 98650bd09..c083c4a9b 100644 --- a/cmd/gnmi-telemetry/telemetry.go +++ b/cmd/gnmi-telemetry/telemetry.go @@ -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) } diff --git a/cmd/gnmi/gnmi.go b/cmd/gnmi/gnmi.go index 62ca0d32e..f6f4eb984 100644 --- a/cmd/gnmi/gnmi.go +++ b/cmd/gnmi/gnmi.go @@ -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) } diff --git a/cmd/gosdn/main.go b/cmd/gosdn/main.go index f6f6c8ee2..4356fbc6a 100644 --- a/cmd/gosdn/main.go +++ b/cmd/gosdn/main.go @@ -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() - } } diff --git a/nucleus/integration.go b/nucleus/integration.go deleted file mode 100644 index 90763e683..000000000 --- a/nucleus/integration.go +++ /dev/null @@ -1,59 +0,0 @@ -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) -} diff --git a/nucleus/integration_test.go b/nucleus/integration_test.go new file mode 100644 index 000000000..003a1802b --- /dev/null +++ b/nucleus/integration_test.go @@ -0,0 +1,39 @@ +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 diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index 7b26ada3e..ec7a80f2b 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -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, diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index 5d77a64dd..1ef15fa9c 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -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 -- GitLab