@@ -7,18 +7,7 @@ import (
7
7
)
8
8
9
9
func TestParseFlakeRef (t * testing.T ) {
10
- // Test cases use the zero-value to check for invalid flakerefs because
11
- // we don't care about the specific error message.
12
10
cases := map [string ]FlakeRef {
13
- // Empty string is not a valid flake reference.
14
- "" : {},
15
-
16
- // Not a path and not a valid URL.
17
- "://bad/url" : {},
18
-
19
- // Invalid escape.
20
- "path:./relative/my%flake" : {},
21
-
22
11
// Path-like references start with a '.' or '/'.
23
12
// This distinguishes them from indirect references
24
13
// (./nixpkgs is a directory; nixpkgs is an indirect).
@@ -35,14 +24,6 @@ func TestParseFlakeRef(t *testing.T) {
35
24
"./Ûñî©ôδ€/flake\n " : {Type : FlakeTypePath , Path : "./Ûñî©ôδ€/flake\n " },
36
25
"/Ûñî©ôδ€/flake\n " : {Type : FlakeTypePath , Path : "/Ûñî©ôδ€/flake\n " },
37
26
38
- // Path-like references don't allow paths with a '?' or '#'.
39
- "./invalid#path" : {},
40
- "./invalid?path" : {},
41
- "/invalid#path" : {},
42
- "/invalid?path" : {},
43
- "/#" : {},
44
- "/?" : {},
45
-
46
27
// URL-like path references.
47
28
"path:" : {Type : FlakeTypePath , Path : "" },
48
29
"path:." : {Type : FlakeTypePath , Path : "." },
@@ -82,12 +63,6 @@ func TestParseFlakeRef(t *testing.T) {
82
63
"github:NixOS/nix?rev=5233fd2ba76a3accb5aaa999c00509a11fd0793c" : {Type : FlakeTypeGitHub , Owner : "NixOS" , Repo : "nix" , Rev : "5233fd2ba76a3accb5aaa999c00509a11fd0793c" },
83
64
"github:NixOS/nix?host=example.com" : {Type : FlakeTypeGitHub , Owner : "NixOS" , Repo : "nix" , Host : "example.com" },
84
65
85
- // GitHub references with invalid ref + rev combinations.
86
- "github:NixOS/nix?ref=v1.2.3&rev=5233fd2ba76a3accb5aaa999c00509a11fd0793c" : {},
87
- "github:NixOS/nix/v1.2.3?ref=v4.5.6" : {},
88
- "github:NixOS/nix/5233fd2ba76a3accb5aaa999c00509a11fd0793c?rev=e486d8d40e626a20e06d792db8cc5ac5aba9a5b4" : {},
89
- "github:NixOS/nix/5233fd2ba76a3accb5aaa999c00509a11fd0793c?ref=v1.2.3" : {},
90
-
91
66
// The github type allows clone-style URLs. The username and
92
67
// host are ignored.
93
68
"github://[email protected] /NixOS/nix" : {
Type :
FlakeTypeGitHub ,
Owner :
"NixOS" ,
Repo :
"nix" },
@@ -142,7 +117,6 @@ func TestParseFlakeRef(t *testing.T) {
142
117
"http://example.com/flake.git" : {Type : FlakeTypeFile , URL : "http://example.com/flake.git" },
143
118
"http://example.com/flake?dir=subdir" : {Type : FlakeTypeFile , URL : "http://example.com/flake?dir=subdir" , Dir : "subdir" },
144
119
}
145
-
146
120
for ref , want := range cases {
147
121
t .Run (ref , func (t * testing.T ) {
148
122
got , err := ParseFlakeRef (ref )
@@ -156,6 +130,67 @@ func TestParseFlakeRef(t *testing.T) {
156
130
}
157
131
}
158
132
133
+ func TestParseFlakeRefError (t * testing.T ) {
134
+ t .Run ("EmptyString" , func (t * testing.T ) {
135
+ ref := ""
136
+ _ , err := ParseFlakeRef (ref )
137
+ if err == nil {
138
+ t .Error ("got nil error for bad flakeref:" , ref )
139
+ }
140
+ })
141
+ t .Run ("InvalidURL" , func (t * testing.T ) {
142
+ ref := "://bad/url"
143
+ _ , err := ParseFlakeRef (ref )
144
+ if err == nil {
145
+ t .Error ("got nil error for bad flakeref:" , ref )
146
+ }
147
+ })
148
+ t .Run ("InvalidURLEscape" , func (t * testing.T ) {
149
+ ref := "path:./relative/my%flake"
150
+ _ , err := ParseFlakeRef (ref )
151
+ if err == nil {
152
+ t .Error ("got nil error for bad flakeref:" , ref )
153
+ }
154
+ })
155
+ t .Run ("UnsupportedURLScheme" , func (t * testing.T ) {
156
+ ref := "runx:mvdan/gofumpt@latest"
157
+ _ , err := ParseFlakeRef (ref )
158
+ if err == nil {
159
+ t .Error ("got nil error for bad flakeref:" , ref )
160
+ }
161
+ })
162
+ t .Run ("PathLikeWith?#" , func (t * testing.T ) {
163
+ in := []string {
164
+ "./invalid#path" ,
165
+ "./invalid?path" ,
166
+ "/invalid#path" ,
167
+ "/invalid?path" ,
168
+ "/#" ,
169
+ "/?" ,
170
+ }
171
+ for _ , ref := range in {
172
+ _ , err := ParseFlakeRef (ref )
173
+ if err == nil {
174
+ t .Error ("got nil error for bad flakeref:" , ref )
175
+ }
176
+ }
177
+ })
178
+ t .Run ("GitHubInvalidRefRevCombo" , func (t * testing.T ) {
179
+ in := []string {
180
+ "github:NixOS/nix?ref=v1.2.3&rev=5233fd2ba76a3accb5aaa999c00509a11fd0793c" ,
181
+ "github:NixOS/nix/v1.2.3?ref=v4.5.6" ,
182
+ "github:NixOS/nix/5233fd2ba76a3accb5aaa999c00509a11fd0793c?rev=e486d8d40e626a20e06d792db8cc5ac5aba9a5b4" ,
183
+ "github:NixOS/nix/5233fd2ba76a3accb5aaa999c00509a11fd0793c?ref=v1.2.3" ,
184
+ }
185
+ for _ , ref := range in {
186
+ _ , err := ParseFlakeRef (ref )
187
+ if err == nil {
188
+ t .Error ("got nil error for bad flakeref:" , ref )
189
+ }
190
+ }
191
+ })
192
+ }
193
+
159
194
func TestFlakeRefString (t * testing.T ) {
160
195
cases := map [FlakeRef ]string {
161
196
{}: "" ,
0 commit comments