This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mgr_chef_berkshelf_test.go
145 lines (122 loc) · 4.99 KB
/
mgr_chef_berkshelf_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package mgr_test
import (
"github.com/stretchr/testify/suite"
"github.com/golang/mock/gomock"
"capsulecd/pkg/mgr/mock"
"capsulecd/pkg/config/mock"
"capsulecd/pkg/pipeline"
"testing"
"io/ioutil"
"github.com/stretchr/testify/require"
"os"
"path"
"capsulecd/pkg/metadata"
"capsulecd/pkg/mgr"
"capsulecd/pkg/utils"
)
// Define the suite, and absorb the built-in basic suite
// functionality from testify - including a T() method which
// returns the current testing context
type MgrChefBerkshelfTestSuite struct {
suite.Suite
MockCtrl *gomock.Controller
Mgr *mock_mgr.MockInterface
Config *mock_config.MockInterface
PipelineData *pipeline.Data
}
// Make sure that VariableThatShouldStartAtFive is set to five
// before each test
func (suite *MgrChefBerkshelfTestSuite) SetupTest() {
suite.MockCtrl = gomock.NewController(suite.T())
suite.PipelineData = new(pipeline.Data)
suite.Config = mock_config.NewMockInterface(suite.MockCtrl)
suite.Mgr = mock_mgr.NewMockInterface(suite.MockCtrl)
}
func (suite *MgrChefBerkshelfTestSuite) TearDownTest() {
suite.MockCtrl.Finish()
}
// In order for 'go test' to run this suite, we need to create
// a normal test function and pass our suite to suite.Run
func TestMgrChefBerkshelf_TestSuite(t *testing.T) {
suite.Run(t, new(MgrChefBerkshelfTestSuite))
}
func (suite *MgrChefBerkshelfTestSuite) TestMgrChefBerkshelfTestSuite_DependenciesStep() {
//setup
suite.Config.EXPECT().SetDefault(gomock.Any(), gomock.Any()).MinTimes(1)
//copy cookbook fixture into a temp directory.
parentPath, err := ioutil.TempDir("", "")
require.NoError(suite.T(), err)
defer os.RemoveAll(parentPath)
suite.PipelineData.GitParentPath = parentPath
suite.PipelineData.GitLocalPath = path.Join(parentPath, "cookbook_analogj_test")
cerr := utils.CopyDir(path.Join("testdata", "chef", "cookbook_analogj_test"), suite.PipelineData.GitLocalPath)
require.NoError(suite.T(), cerr)
mgrChefBerkshelf, err := mgr.Create("berkshelf", suite.PipelineData, suite.Config, nil)
require.NoError(suite.T(), err)
currentVersion := new(metadata.ChefMetadata)
nextVersion := new(metadata.ChefMetadata)
//test
berr := mgrChefBerkshelf.MgrDependenciesStep(currentVersion, nextVersion)
//assert
require.NoError(suite.T(), berr)
require.True(suite.T(), utils.FileExists(path.Join(suite.PipelineData.GitLocalPath, "Berksfile.lock")))
require.True(suite.T(), utils.FileExists(path.Join(suite.PipelineData.GitLocalPath, "Gemfile.lock")))
}
func (suite *MgrChefBerkshelfTestSuite) TestMgrChefBerkshelfTestSuite_WithoutCredentials() {
//setup
suite.Config.EXPECT().SetDefault(gomock.Any(), gomock.Any()).MinTimes(1)
suite.Config.EXPECT().IsSet("chef_supermarket_username").MinTimes(1).Return(false)
mgrChefBerkshelf, err := mgr.Create("berkshelf", suite.PipelineData, suite.Config, nil)
require.NoError(suite.T(), err)
currentVersion := new(metadata.ChefMetadata)
nextVersion := new(metadata.ChefMetadata)
//test
berr := mgrChefBerkshelf.MgrDistStep(currentVersion, nextVersion)
//assert
require.Error(suite.T(), berr)
}
//
//// junk username/password only for use on test.pypi.org
//// username: capsulecd
//// password: capsulecd$23$
//// we're not going to mock out this test, as we want to ensure that package manager integration works correctly, so we'll just
//// communicate with the test pypi server.
//func (suite *MgrPythonPipTestSuite) TestMgrChefBerkshelfTestSuite_DistStep_WithCredentials() {
// //setup
// //suite.Config.EXPECT().SetDefault(gomock.Any(), gomock.Any()).MinTimes(1)
// suite.Config.EXPECT().IsSet("pypi_username").MinTimes(1).Return(true)
// suite.Config.EXPECT().IsSet("pypi_password").MinTimes(1).Return(true)
// suite.Config.EXPECT().GetString("pypi_username").MinTimes(1).Return("capsulecd")
// suite.Config.EXPECT().GetString("pypi_password").MinTimes(1).Return("capsulecd$23$")
// suite.Config.EXPECT().GetString("pypi_repository").MinTimes(1).Return("https://test.pypi.org/legacy/") //using test repo
//
//
// //copy cookbook fixture into a temp directory.
// parentPath, err := ioutil.TempDir("", "")
// require.NoError(suite.T(), err)
// defer os.RemoveAll(parentPath)
// suite.PipelineData.GitParentPath = parentPath
// suite.PipelineData.GitLocalPath = path.Join(parentPath, "pip_analogj_test")
// cerr := utils.CopyDir(path.Join("testdata", "python", "pip_analogj_test"), suite.PipelineData.GitLocalPath)
// require.NoError(suite.T(), cerr)
//
//
// //using current date/time as a pseudo version number
// t := time.Now()
// dateVersion := t.Format("20060102.1504.05") //yyyymmdd.HHMM.SS
// werr := ioutil.WriteFile(path.Join(suite.PipelineData.GitLocalPath, "VERSION"), []byte(dateVersion), 0644)
// require.NoError(suite.T(), werr)
//
//
// mgrPythonPip, err := mgr.Create("pip", suite.PipelineData, suite.Config, nil)
// require.NoError(suite.T(), err)
//
// currentVersion := new(metadata.PythonMetadata)
// nextVersion := new(metadata.PythonMetadata)
//
// //test
// berr := mgrPythonPip.MgrDistStep(currentVersion, nextVersion)
//
// //assert
// require.NoError(suite.T(), berr)
//}