From 7fc27f0ef497da9659bc6b3b3b74c593cfcb2cf9 Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Mon, 6 Aug 2018 18:34:59 -0700 Subject: [PATCH] Add test for content sha --- pkg/cli/watch.go | 2 +- pkg/specs/chart_test.go | 29 ++++++++++++++++++++++ pkg/test-mocks/dockerlayer/archive_mock.go | 25 +++++++++++++++++++ pkg/test-mocks/state/manager_mock.go | 12 +++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/pkg/cli/watch.go b/pkg/cli/watch.go index 968c6b9f6..4392d8476 100644 --- a/pkg/cli/watch.go +++ b/pkg/cli/watch.go @@ -15,7 +15,7 @@ func Watch() *cobra.Command { cmd := &cobra.Command{ Use: "watch", Short: "Watch an upstream for updates", - Long: `Watch will poll the upstream source for changes, and block until a + Long: `Watch will poll the upstream source for changes, and block until a change has been published. The watch command will return with an exit code of 0 when there's an update available.`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/pkg/specs/chart_test.go b/pkg/specs/chart_test.go index c49c67b34..a0b07c88c 100644 --- a/pkg/specs/chart_test.go +++ b/pkg/specs/chart_test.go @@ -14,11 +14,13 @@ import ( "github.com/go-kit/kit/log" "github.com/replicatedhq/ship/pkg/constants" + "github.com/replicatedhq/ship/pkg/state" "github.com/google/go-github/github" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/spf13/afero" + "github.com/spf13/viper" ) var client *github.Client @@ -151,6 +153,33 @@ var _ = Describe("GithubClient", func() { }) }) }) + + Describe("calculateContentSHA", func() { + Context("With multiple files", func() { + It("should calculate the same sha, mulitple times", func() { + mockFs := afero.Afero{Fs: afero.NewMemMapFs()} + mockFs.WriteFile("Chart.yaml", []byte("chart.yaml"), 0755) + mockFs.WriteFile("templates/README.md", []byte("readme"), 0755) + + r := Resolver{ + FS: mockFs, + StateManager: &state.MManager{ + Logger: log.NewNopLogger(), + FS: mockFs, + V: viper.New(), + }, + } + + firstPass, err := r.calculateContentSHA("") + Expect(err).NotTo(HaveOccurred()) + + secondPass, err := r.calculateContentSHA("") + Expect(err).NotTo(HaveOccurred()) + + Expect(firstPass).To(Equal(secondPass)) + }) + }) + }) }) var _ = AfterSuite(func() { diff --git a/pkg/test-mocks/dockerlayer/archive_mock.go b/pkg/test-mocks/dockerlayer/archive_mock.go index c0da92327..d11fea8aa 100644 --- a/pkg/test-mocks/dockerlayer/archive_mock.go +++ b/pkg/test-mocks/dockerlayer/archive_mock.go @@ -5,6 +5,7 @@ package dockerlayer import ( + io "io" reflect "reflect" gomock "github.com/golang/mock/gomock" @@ -68,3 +69,27 @@ func (m *MockArchiver) Open(arg0, arg1 string) error { func (mr *MockArchiverMockRecorder) Open(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockArchiver)(nil).Open), arg0, arg1) } + +// Read mocks base method +func (m *MockArchiver) Read(arg0 io.Reader, arg1 string) error { + ret := m.ctrl.Call(m, "Read", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Read indicates an expected call of Read +func (mr *MockArchiverMockRecorder) Read(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockArchiver)(nil).Read), arg0, arg1) +} + +// Write mocks base method +func (m *MockArchiver) Write(arg0 io.Writer, arg1 []string) error { + ret := m.ctrl.Call(m, "Write", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Write indicates an expected call of Write +func (mr *MockArchiverMockRecorder) Write(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*MockArchiver)(nil).Write), arg0, arg1) +} diff --git a/pkg/test-mocks/state/manager_mock.go b/pkg/test-mocks/state/manager_mock.go index dee2aeb31..2d0446d96 100644 --- a/pkg/test-mocks/state/manager_mock.go +++ b/pkg/test-mocks/state/manager_mock.go @@ -95,6 +95,18 @@ func (mr *MockManagerMockRecorder) SerializeConfig(arg0, arg1, arg2 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SerializeConfig", reflect.TypeOf((*MockManager)(nil).SerializeConfig), arg0, arg1, arg2) } +// SerializeContentSHA mocks base method +func (m *MockManager) SerializeContentSHA(arg0 string) error { + ret := m.ctrl.Call(m, "SerializeContentSHA", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// SerializeContentSHA indicates an expected call of SerializeContentSHA +func (mr *MockManagerMockRecorder) SerializeContentSHA(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SerializeContentSHA", reflect.TypeOf((*MockManager)(nil).SerializeContentSHA), arg0) +} + // SerializeHelmValues mocks base method func (m *MockManager) SerializeHelmValues(arg0 string) error { ret := m.ctrl.Call(m, "SerializeHelmValues", arg0)