6
6
"path/filepath"
7
7
"testing"
8
8
9
+ "github.com/containous/structor/types"
9
10
"github.com/stretchr/testify/assert"
10
11
"github.com/stretchr/testify/require"
11
12
)
@@ -52,40 +53,48 @@ func Test_getDocumentationRoot(t *testing.T) {
52
53
defer func () { _ = os .RemoveAll (workingDirBasePath ) }()
53
54
require .NoError (t , err )
54
55
56
+ type expected struct {
57
+ docsRoot string
58
+ error string
59
+ }
60
+
55
61
testCases := []struct {
56
- desc string
57
- workingDirectory string
58
- repositoryFiles []string
59
- expectedDocsRoot string
60
- expectedErrorMessage string
62
+ desc string
63
+ workingDirectory string
64
+ repositoryFiles []string
65
+ expected expected
61
66
}{
62
67
{
63
- desc : "working case with mkdocs in the root of the repository" ,
64
- workingDirectory : filepath .Join (workingDirBasePath , "mkdocs-in-root" ),
65
- repositoryFiles : []string {"mkdocs.yml" , "requirements.txt" , "docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
66
- expectedDocsRoot : filepath .Join (workingDirBasePath , "mkdocs-in-root" ),
67
- expectedErrorMessage : "" ,
68
+ desc : "working case with mkdocs in the root of the repository" ,
69
+ workingDirectory : filepath .Join (workingDirBasePath , "mkdocs-in-root" ),
70
+ repositoryFiles : []string {"mkdocs.yml" , "requirements.txt" , "docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
71
+ expected : expected {
72
+ docsRoot : filepath .Join (workingDirBasePath , "mkdocs-in-root" ),
73
+ },
68
74
},
69
75
{
70
- desc : "working case with mkdocs in ./docs" ,
71
- workingDirectory : filepath .Join (workingDirBasePath , "mkdocs-in-docs" ),
72
- repositoryFiles : []string {"docs/mkdocs.yml" , "docs/requirements.txt" , "docs/docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
73
- expectedDocsRoot : filepath .Join (workingDirBasePath , "mkdocs-in-docs" , "docs" ),
74
- expectedErrorMessage : "" ,
76
+ desc : "working case with mkdocs in ./docs" ,
77
+ workingDirectory : filepath .Join (workingDirBasePath , "mkdocs-in-docs" ),
78
+ repositoryFiles : []string {"docs/mkdocs.yml" , "docs/requirements.txt" , "docs/docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
79
+ expected : expected {
80
+ docsRoot : filepath .Join (workingDirBasePath , "mkdocs-in-docs" , "docs" ),
81
+ },
75
82
},
76
83
{
77
- desc : "error case with no mkdocs file found in the search path" ,
78
- workingDirectory : filepath .Join (workingDirBasePath , "no-mkdocs-in-search-path" ),
79
- repositoryFiles : []string {"documentation/mkdocs.yml" , "documentation/requirements.txt" , "documentation/docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
80
- expectedDocsRoot : "" ,
81
- expectedErrorMessage : "no file mkdocs.yml found in " + workingDirBasePath + "/no-mkdocs-in-search-path (search path was: /,docs/)" ,
84
+ desc : "error case with no mkdocs file found in the search path" ,
85
+ workingDirectory : filepath .Join (workingDirBasePath , "no-mkdocs-in-search-path" ),
86
+ repositoryFiles : []string {"documentation/mkdocs.yml" , "documentation/requirements.txt" , "documentation/docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
87
+ expected : expected {
88
+ error : "no file mkdocs.yml found in " + workingDirBasePath + "/no-mkdocs-in-search-path (search path was: /, docs/)" ,
89
+ },
82
90
},
83
91
{
84
- desc : "error case with no mkdocs file found at all" ,
85
- workingDirectory : filepath .Join (workingDirBasePath , "no-mkdocs-at-all" ),
86
- repositoryFiles : []string {"docs/requirements.txt" , "docs/docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
87
- expectedDocsRoot : "" ,
88
- expectedErrorMessage : "no file mkdocs.yml found in " + workingDirBasePath + "/no-mkdocs-at-all (search path was: /,docs/)" ,
92
+ desc : "error case with no mkdocs file found at all" ,
93
+ workingDirectory : filepath .Join (workingDirBasePath , "no-mkdocs-at-all" ),
94
+ repositoryFiles : []string {"docs/requirements.txt" , "docs/docs.Dockerfile" , ".gitignore" , "docs/index.md" , ".github/ISSUE.md" },
95
+ expected : expected {
96
+ error : "no file mkdocs.yml found in " + workingDirBasePath + "/no-mkdocs-at-all (search path was: /, docs/)" ,
97
+ },
89
98
},
90
99
}
91
100
@@ -108,18 +117,78 @@ func Test_getDocumentationRoot(t *testing.T) {
108
117
}
109
118
}
110
119
111
- resultingDocsRoot , resultingError := getDocumentationRoot (test .workingDirectory )
120
+ docsRoot , err := getDocumentationRoot (test .workingDirectory )
112
121
113
- if test .expectedErrorMessage != "" {
114
- assert .EqualError (t , resultingError , test .expectedErrorMessage )
122
+ if test .expected . error != "" {
123
+ assert .EqualError (t , err , test .expected . error )
115
124
} else {
116
- require .NoError (t , resultingError )
117
- assert .Equal (t , test .expectedDocsRoot , resultingDocsRoot )
125
+ require .NoError (t , err )
126
+ assert .Equal (t , test .expected . docsRoot , docsRoot )
118
127
}
119
128
})
120
129
}
121
130
}
122
131
132
+ func Test_getDocsDirSuffix (t * testing.T ) {
133
+ testCases := []struct {
134
+ desc string
135
+ version types.VersionsInformation
136
+ expected string
137
+ }{
138
+ {
139
+ desc : "no suffix" ,
140
+ version : types.VersionsInformation {
141
+ CurrentPath : "/tmp/structor694968263/v2.0" ,
142
+ Current : "v2.0" ,
143
+ },
144
+ expected : "" ,
145
+ },
146
+ {
147
+ desc : "simple suffix" ,
148
+ version : types.VersionsInformation {
149
+ CurrentPath : "/tmp/structor694968263/v2.0/docs" ,
150
+ Current : "v2.0" ,
151
+ },
152
+ expected : "docs" ,
153
+ },
154
+ {
155
+ desc : "suffix with slash" ,
156
+ version : types.VersionsInformation {
157
+ CurrentPath : "/tmp/structor694968263/v2.0/docs/" ,
158
+ Current : "v2.0" ,
159
+ },
160
+ expected : "docs" ,
161
+ },
162
+ {
163
+ desc : "long suffix" ,
164
+ version : types.VersionsInformation {
165
+ CurrentPath : "/tmp/structor694968263/v2.0/docs/foo" ,
166
+ Current : "v2.0" ,
167
+ },
168
+ expected : "docs/foo" ,
169
+ },
170
+ {
171
+ desc : "contains two times the version path" ,
172
+ version : types.VersionsInformation {
173
+ CurrentPath : "/tmp/structor694968263/v2.0/docs/foo/v2.0/bar" ,
174
+ Current : "v2.0" ,
175
+ },
176
+ expected : "docs/foo/v2.0/bar" ,
177
+ },
178
+ }
179
+
180
+ for _ , test := range testCases {
181
+ test := test
182
+ t .Run (test .desc , func (t * testing.T ) {
183
+ t .Parallel ()
184
+
185
+ suffix := getDocsDirSuffix (test .version )
186
+
187
+ assert .Equal (t , test .expected , suffix )
188
+ })
189
+ }
190
+ }
191
+
123
192
func Test_createDirectory (t * testing.T ) {
124
193
dir , err := ioutil .TempDir ("" , "structor-test" )
125
194
require .NoError (t , err )
0 commit comments