Share artifact declaration validation
This commit is contained in:
@@ -56,3 +56,31 @@ func TestValidComponentPreservesBuildAndReceiptRules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateDeclarationsMatchesTargetsAndNames(t *testing.T) {
|
||||
linux := Target{OS: "linux", Arch: "amd64"}
|
||||
windows := Target{OS: "windows", Arch: "arm64"}
|
||||
first := Declaration{Target: linux, Filename: "app-v1.2.3-linux-amd64"}
|
||||
second := Declaration{Target: windows, Filename: "app-v1.2.3-windows-arm64.exe"}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
targets []Target
|
||||
recorded []Declaration
|
||||
valid bool
|
||||
}{
|
||||
{"reordered", []Target{linux, windows}, []Declaration{second, first}, true},
|
||||
{"count", []Target{linux, windows}, []Declaration{first}, false},
|
||||
{"duplicate target", []Target{linux, linux}, []Declaration{first, first}, false},
|
||||
{"duplicate artifact", []Target{linux, windows}, []Declaration{first, first}, false},
|
||||
{"incorrect name", []Target{linux}, []Declaration{{Target: linux, Filename: "other"}}, false},
|
||||
{"unknown target", []Target{linux}, []Declaration{second}, false},
|
||||
{"unsafe target", []Target{{OS: "linux/other", Arch: "amd64"}}, []Declaration{{Target: linux, Filename: first.Filename}}, false},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := ValidateDeclarations("app", "v1.2.3", test.targets, test.recorded)
|
||||
if (err == nil) != test.valid {
|
||||
t.Fatalf("ValidateDeclarations() error = %v, valid = %t", err, test.valid)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user