[ISSUE-66918282] update tests
diff --git a/cover.sh b/cover.sh new file mode 100755 index 0000000..85bbc35 --- /dev/null +++ b/cover.sh
@@ -0,0 +1,27 @@ +#!/bin/bash -eu +# +# Copyright 2017 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/usr/bin/env bash + +set -e +echo "mode: atomic" > coverage.txt + +go test -coverprofile=profile.out -covermode=atomic github.com/apid/apidGatewayConfDeploy +if [ -f profile.out ]; then + tail -n +2 profile.out >> coverage.txt + rm profile.out +fi +go tool cover -html=coverage.txt -o cover.html
diff --git a/data.go b/data.go index 9734130..e99cba7 100644 --- a/data.go +++ b/data.go
@@ -187,6 +187,7 @@ return } +/* func (dbc *dbManager) getReadyConfigurations(typeFilter string) ([]Configuration, error) { // An alternative statement is in get_ready_deployments.sql @@ -295,7 +296,7 @@ return confs, nil } - +*/ func (dbc *dbManager) getAllConfigurations(typeFilter string) ([]Configuration, error) { // An alternative statement is in get_ready_deployments.sql
diff --git a/data_test.go b/data_test.go index e8114c3..65aace8 100644 --- a/data_test.go +++ b/data_test.go
@@ -163,16 +163,18 @@ It("should get empty slice if no configurations", func() { trancateTestMetadataTable(testDbMan.getDb()) - confs, err := testDbMan.getReadyConfigurations("") + confs, err := testDbMan.getAllConfigurations("") Expect(err).Should(Succeed()) Expect(len(confs)).Should(BeZero()) }) - XIt("should get empty slice if no configurations are ready", func() { - confs, err := testDbMan.getReadyConfigurations("") - Expect(err).Should(Succeed()) - Expect(len(confs)).Should(BeZero()) - }) + /* + XIt("should get empty slice if no configurations are ready", func() { + confs, err := testDbMan.getReadyConfigurations("") + Expect(err).Should(Succeed()) + Expect(len(confs)).Should(BeZero()) + }) + */ It("should succefully update local FS location", func() { @@ -229,24 +231,25 @@ Expect(err).ShouldNot(Succeed()) }) - XIt("should successfully get all ready configurations", func() { + /* + XIt("should successfully get all ready configurations", func() { - err := testDbMan.updateLocalFsLocation(readyBlobId, testBlobLocalFsPrefix+readyBlobId) - Expect(err).Should(Succeed()) - err = testDbMan.updateLocalFsLocation(readyResourceId, testBlobLocalFsPrefix+readyResourceId) - Expect(err).Should(Succeed()) + err := testDbMan.updateLocalFsLocation(readyBlobId, testBlobLocalFsPrefix+readyBlobId) + Expect(err).Should(Succeed()) + err = testDbMan.updateLocalFsLocation(readyResourceId, testBlobLocalFsPrefix+readyResourceId) + Expect(err).Should(Succeed()) - confs, err := testDbMan.getReadyConfigurations("") - Expect(err).Should(Succeed()) - Expect(len(confs)).Should(Equal(2)) - for _, conf := range confs { - Expect(conf.BlobID).Should(Equal(readyBlobId)) - if conf.BlobResourceID != "" { - Expect(conf.BlobResourceID).Should(Equal(readyResourceId)) + confs, err := testDbMan.getReadyConfigurations("") + Expect(err).Should(Succeed()) + Expect(len(confs)).Should(Equal(2)) + for _, conf := range confs { + Expect(conf.BlobID).Should(Equal(readyBlobId)) + if conf.BlobResourceID != "" { + Expect(conf.BlobResourceID).Should(Equal(readyResourceId)) + } } - } - }) - + }) + */ It("should get all configurations by type filter", func() { err := testDbMan.updateLocalFsLocation(readyBlobId, testBlobLocalFsPrefix+readyBlobId)
diff --git a/listener.go b/listener.go index f77d306..b203187 100644 --- a/listener.go +++ b/listener.go
@@ -69,9 +69,14 @@ } if lsn := h.dbMan.getLSN(); lsn != "" { - h.dbMan.updateLSN(lsn) + // receive a new snapshot at runtime + if err = h.dbMan.updateLSN(lsn); err != nil { + log.Errorf("Unable to update LSN: %v", err) + } } else { //apid just started - h.dbMan.loadLsnFromDb() + if err = h.dbMan.loadLsnFromDb(); err != nil { + log.Errorf("Unable to load LSN From Db: %v", err) + } } h.startupOnExistingDatabase() //h.apiMan.InitAPI()
diff --git a/listener_test.go b/listener_test.go index d08934e..2971a08 100644 --- a/listener_test.go +++ b/listener_test.go
@@ -40,9 +40,7 @@ notifyChan: make(chan bool, 1), initCalled: make(chan bool), } - dummyDbMan = &dummyDbManager{ - lsn: "0.0.1", - } + dummyDbMan = &dummyDbManager{} dummyBundleMan = &dummyBundleManager{ blobChan: make(chan string), } @@ -115,6 +113,27 @@ Expect(<-dummyApiMan.notifyChan).Should(BeTrue()) }) + It("Should load LSN when apid starts", func() { + dummyDbMan.dbLSN = fmt.Sprintf("%d.%d.%d", testCount, testCount, testCount) + // emit snapshot + version := fmt.Sprint(rand.Uint32()) + snapshot := &common.Snapshot{ + SnapshotInfo: version, + } + <-apid.Events().Emit(APIGEE_SYNC_EVENT, snapshot) + Expect(dummyDbMan.getLSN()).Should(Equal(dummyDbMan.dbLSN)) + }) + + It("Should store LSN when receiving snapshot at runtime", func() { + dummyDbMan.lsn = fmt.Sprintf("%d.%d.%d", testCount, testCount, testCount) + // emit snapshot + version := fmt.Sprint(rand.Uint32()) + snapshot := &common.Snapshot{ + SnapshotInfo: version, + } + <-apid.Events().Emit(APIGEE_SYNC_EVENT, snapshot) + Expect(dummyDbMan.getLSN()).Should(Equal(dummyDbMan.dbLSN)) + }) }) Context("Change list", func() { @@ -221,6 +240,11 @@ }) Context("LSN", func() { + + var _ = BeforeEach(func() { + dummyDbMan.lsn = "0.0.1" + }) + It("changelist with CONFIG_METADATA_TABLE should update apidLSN", func() { // emit change event changes := make([]common.Change, 0)
diff --git a/mock_test.go b/mock_test.go index b272eaf..f8f804a 100644 --- a/mock_test.go +++ b/mock_test.go
@@ -22,6 +22,7 @@ version string configurations map[string]*Configuration lsn string + dbLSN string err error } @@ -74,11 +75,12 @@ func (d *dummyDbManager) updateLSN(LSN string) error { d.lsn = LSN + d.dbLSN = LSN return nil } func (d *dummyDbManager) loadLsnFromDb() error { - + d.lsn = d.dbLSN return nil }