-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
- Loading branch information
1 parent
8504a9e
commit 4d50e02
Showing
5 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
Copyright 2023 Stefan Prodan | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func Test_BundleLint(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
bundle string | ||
matchErr string | ||
}{ | ||
{ | ||
name: "fails for invalid API Version", | ||
matchErr: "bundle.apiVersion", | ||
bundle: ` | ||
bundle: { | ||
apiVersion: "v1alpha2" | ||
instances: { | ||
test: { | ||
module: { | ||
url: "oci://docker.io/test" | ||
version: "latest" | ||
} | ||
namespace: "default" | ||
values: {} | ||
} | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
name: "fails for invalid module URL", | ||
matchErr: "bundle.instances.test.module.url", | ||
bundle: ` | ||
bundle: { | ||
apiVersion: "v1alpha1" | ||
instances: { | ||
test: { | ||
module: { | ||
url: "docker.io/test" | ||
version: "latest" | ||
} | ||
namespace: "default" | ||
values: {} | ||
} | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
name: "fails for missing module version", | ||
matchErr: "bundle.instances.test.module.version", | ||
bundle: ` | ||
bundle: { | ||
apiVersion: "v1alpha1" | ||
instances: { | ||
test: { | ||
module: { | ||
url: "oci://docker.io/test" | ||
} | ||
namespace: "default" | ||
values: {} | ||
} | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
name: "fails for invalid module prop", | ||
matchErr: "url2", | ||
bundle: ` | ||
bundle: { | ||
apiVersion: "v1alpha1" | ||
instances: { | ||
test: { | ||
module: { | ||
url2: "oci://docker.io/test" | ||
version: "latest" | ||
} | ||
namespace: "default" | ||
values: {} | ||
} | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
name: "fails for missing namespace", | ||
matchErr: "bundle.instances.test.namespace", | ||
bundle: ` | ||
bundle: { | ||
apiVersion: "v1alpha1" | ||
instances: { | ||
test: { | ||
module: { | ||
url: "oci://docker.io/test" | ||
version: "latest" | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
name: "fails for missing instances", | ||
matchErr: "no instances", | ||
bundle: ` | ||
bundle: { | ||
apiVersion: "v1alpha1" | ||
instances: {} | ||
} | ||
`, | ||
}, | ||
} | ||
|
||
tmpDir := t.TempDir() | ||
for i, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
bundlePath := filepath.Join(tmpDir, fmt.Sprintf("bundle-%v.cue", i)) | ||
err := os.WriteFile(bundlePath, []byte(tt.bundle), 0644) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
|
||
_, err = executeCommand(fmt.Sprintf( | ||
"bundle lint -f %s", | ||
bundlePath, | ||
)) | ||
|
||
g.Expect(err).To(HaveOccurred()) | ||
g.Expect(err.Error()).To(MatchRegexp(tt.matchErr)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters