Warning if version of Devfile is different from 2.2.0 (#7065)

* Warning if version of Devfile is different from 2.2.0

* Fix unit tests
This commit is contained in:
Philippe Martin
2023-09-05 11:30:51 +02:00
committed by GitHub
parent e21b80f72a
commit 3f93ac0744
13 changed files with 38 additions and 2 deletions

View File

@@ -1642,6 +1642,7 @@ components:
type: object type: object
required: required:
- content - content
- version
- commands - commands
- containers - containers
- images - images
@@ -1652,6 +1653,8 @@ components:
properties: properties:
content: content:
type: string type: string
version:
type: string
commands: commands:
type: array type: array
items: items:

View File

@@ -12,6 +12,8 @@ package openapi
type DevfileContent struct { type DevfileContent struct {
Content string `json:"content"` Content string `json:"content"`
Version string `json:"version"`
Commands []Command `json:"commands"` Commands []Command `json:"commands"`
Containers []Container `json:"containers"` Containers []Container `json:"containers"`
@@ -31,6 +33,7 @@ type DevfileContent struct {
func AssertDevfileContentRequired(obj DevfileContent) error { func AssertDevfileContentRequired(obj DevfileContent) error {
elements := map[string]interface{}{ elements := map[string]interface{}{
"content": obj.Content, "content": obj.Content,
"version": obj.Version,
"commands": obj.Commands, "commands": obj.Commands,
"containers": obj.Containers, "containers": obj.Containers,
"images": obj.Images, "images": obj.Images,

View File

@@ -83,6 +83,7 @@ components:
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{ Commands: []Command{
{ {
Name: "an-exec-command", Name: "an-exec-command",
@@ -183,6 +184,7 @@ components:
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{ Commands: []Command{
{ {
Name: "an-apply-command", Name: "an-apply-command",
@@ -311,6 +313,7 @@ components:
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{ Commands: []Command{
{ {
Name: "an-exec-command", Name: "an-exec-command",
@@ -440,6 +443,7 @@ func TestDevfileState_DeleteCommand(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{ Containers: []Container{
{ {
@@ -655,6 +659,7 @@ func TestDevfileState_MoveCommand(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{ Commands: []Command{
{ {
Name: "an-exec-command", Name: "an-exec-command",
@@ -742,6 +747,7 @@ func TestDevfileState_SetDefaultCommand(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{ Commands: []Command{
{ {
Name: "an-exec-command", Name: "an-exec-command",
@@ -831,6 +837,7 @@ func TestDevfileState_UnsetDefaultCommand(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{ Commands: []Command{
{ {
Name: "an-exec-command", Name: "an-exec-command",

View File

@@ -78,6 +78,7 @@ func TestDevfileState_AddContainer(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{ Containers: []Container{
{ {
@@ -150,6 +151,7 @@ schemaVersion: 2.2.0
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{ Containers: []Container{
{ {
@@ -243,6 +245,7 @@ func TestDevfileState_DeleteContainer(t *testing.T) {
Content: `metadata: {} Content: `metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},
@@ -349,6 +352,7 @@ func TestDevfileState_AddImage(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{ Images: []Image{
@@ -424,6 +428,7 @@ func TestDevfileState_DeleteImage(t *testing.T) {
Content: `metadata: {} Content: `metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},
@@ -507,6 +512,7 @@ func TestDevfileState_AddResource(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},
@@ -539,6 +545,7 @@ schemaVersion: 2.2.0
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},
@@ -607,6 +614,7 @@ func TestDevfileState_Deleteresource(t *testing.T) {
Content: `metadata: {} Content: `metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},
@@ -688,6 +696,7 @@ func TestDevfileState_AddVolume(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},
@@ -753,6 +762,7 @@ func TestDevfileState_DeleteVolume(t *testing.T) {
Content: `metadata: {} Content: `metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},

View File

@@ -54,6 +54,7 @@ func (o *DevfileState) GetContent() (DevfileContent, error) {
return DevfileContent{ return DevfileContent{
Content: string(result), Content: string(result),
Version: o.Devfile.Data.GetSchemaVersion(),
Commands: commands, Commands: commands,
Containers: containers, Containers: containers,
Images: images, Images: images,

View File

@@ -20,6 +20,7 @@ func TestDevfileState_GetContent(t *testing.T) {
}, },
want: DevfileContent{ want: DevfileContent{
Content: "metadata: {}\nschemaVersion: 2.2.0\n", Content: "metadata: {}\nschemaVersion: 2.2.0\n",
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},

View File

@@ -35,6 +35,7 @@ func TestDevfileState_UpdateEvents(t *testing.T) {
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},
@@ -67,6 +68,7 @@ schemaVersion: 2.2.0
metadata: {} metadata: {}
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},

View File

@@ -71,6 +71,7 @@ func TestDevfileState_SetMetadata(t *testing.T) {
website: http://example.com website: http://example.com
schemaVersion: 2.2.0 schemaVersion: 2.2.0
`, `,
Version: "2.2.0",
Commands: []Command{}, Commands: []Command{},
Containers: []Container{}, Containers: []Container{},
Images: []Image{}, Images: []Image{},

View File

@@ -1642,6 +1642,7 @@ components:
type: object type: object
required: required:
- content - content
- version
- commands - commands
- containers - containers
- images - images
@@ -1652,6 +1653,8 @@ components:
properties: properties:
content: content:
type: string type: string
version:
type: string
commands: commands:
type: array type: array
items: items:

View File

@@ -11,6 +11,6 @@
<body class="mat-typography"> <body class="mat-typography">
<div id="loading">Loading, please wait...</div> <div id="loading">Loading, please wait...</div>
<app-root></app-root> <app-root></app-root>
<script src="runtime.1289ea0acffcdc5e.js" type="module"></script><script src="polyfills.8b3b37cedaf377c3.js" type="module"></script><script src="main.113aa354c1f3bda4.js" type="module"></script> <script src="runtime.1289ea0acffcdc5e.js" type="module"></script><script src="polyfills.8b3b37cedaf377c3.js" type="module"></script><script src="main.4d8dc3ef32c88ca3.js" type="module"></script>
</body></html> </body></html>

File diff suppressed because one or more lines are too long

View File

@@ -20,6 +20,7 @@ import { Image } from './image';
export interface DevfileContent { export interface DevfileContent {
content: string; content: string;
version: string;
commands: Array<Command>; commands: Array<Command>;
containers: Array<Container>; containers: Array<Container>;
images: Array<Image>; images: Array<Image>;

View File

@@ -84,6 +84,10 @@ export class AppComponent implements OnInit {
console.log(error); console.log(error);
} }
}); });
if (newContent.version != "2.2.0") {
this.snackbar.open("The version of the Devfile is "+newContent.version+".\nOnly version 2.2.0 is supported", "ok")
}
}); });
this.sse.subscribeTo(['DevfileUpdated']).subscribe(event => { this.sse.subscribeTo(['DevfileUpdated']).subscribe(event => {