Merge pull request #131 from jakalkhalili/fix-plugin-version
Fix plugin version validation
This commit is contained in:
		
						commit
						0f5206e150
					
				|  | @ -57,7 +57,7 @@ func TestValidatePlugins(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 		got := baseReconcileLoop.validatePlugins(requiredBasePlugins, basePlugins, userPlugins) | 		got := baseReconcileLoop.validatePlugins(requiredBasePlugins, basePlugins, userPlugins) | ||||||
| 
 | 
 | ||||||
| 		assert.Equal(t, got, []string{"invalid plugin version 'simple-plugin:invalid', must follow pattern '^[0-9\\\\.]+$'"}) | 		assert.Equal(t, got, []string{"invalid plugin version 'simple-plugin:invalid', must follow pattern '^[0-9\\\\.-]+$'"}) | ||||||
| 	}) | 	}) | ||||||
| 	t.Run("valid base plugin", func(t *testing.T) { | 	t.Run("valid base plugin", func(t *testing.T) { | ||||||
| 		var requiredBasePlugins []plugins.Plugin | 		var requiredBasePlugins []plugins.Plugin | ||||||
|  | @ -84,7 +84,7 @@ func TestValidatePlugins(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 		got := baseReconcileLoop.validatePlugins(requiredBasePlugins, basePlugins, userPlugins) | 		got := baseReconcileLoop.validatePlugins(requiredBasePlugins, basePlugins, userPlugins) | ||||||
|      |      | ||||||
| 		assert.Equal(t, got, []string{"invalid plugin version 'simple-plugin:invalid', must follow pattern '^[0-9\\\\.]+$'"}) | 		assert.Equal(t, got, []string{"invalid plugin version 'simple-plugin:invalid', must follow pattern '^[0-9\\\\.-]+$'"}) | ||||||
| 	}) | 	}) | ||||||
| 	t.Run("valid user and base plugin version", func(t *testing.T) { | 	t.Run("valid user and base plugin version", func(t *testing.T) { | ||||||
| 		var requiredBasePlugins []plugins.Plugin | 		var requiredBasePlugins []plugins.Plugin | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ func (p Plugin) String() string { | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
| 	namePattern    = regexp.MustCompile(`(?i)^[0-9a-z-_]+$`) | 	namePattern    = regexp.MustCompile(`(?i)^[0-9a-z-_]+$`) | ||||||
| 	versionPattern = regexp.MustCompile(`^[0-9\\.]+$`) | 	versionPattern = regexp.MustCompile(`^[0-9\\.-]+$`) | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // New creates plugin from string, for example "name-of-plugin:0.0.1"
 | // New creates plugin from string, for example "name-of-plugin:0.0.1"
 | ||||||
|  |  | ||||||
|  | @ -115,4 +115,13 @@ func TestVerifyDependencies(t *testing.T) { | ||||||
| 		assert.Contains(t, got, "Plugin 'first-root-plugin:1.0.0' requires version '0.0.1' but plugin 'first-root-plugin:2.0.0' requires '0.0.2' for plugin 'first-plugin'") | 		assert.Contains(t, got, "Plugin 'first-root-plugin:1.0.0' requires version '0.0.1' but plugin 'first-root-plugin:2.0.0' requires '0.0.2' for plugin 'first-plugin'") | ||||||
| 		assert.Contains(t, got, "Plugin 'first-root-plugin:2.0.0' requires version '0.0.2' but plugin 'first-root-plugin:1.0.0' requires '0.0.1' for plugin 'first-plugin'") | 		assert.Contains(t, got, "Plugin 'first-root-plugin:2.0.0' requires version '0.0.2' but plugin 'first-root-plugin:1.0.0' requires '0.0.1' for plugin 'first-plugin'") | ||||||
| 	}) | 	}) | ||||||
|  | 	t.Run("happy with dash in version", func(t *testing.T) { | ||||||
|  | 		basePlugins := map[Plugin][]Plugin{ | ||||||
|  | 			Must(New("first-root-plugin:1.0.0-1")): { | ||||||
|  | 				Must(New("first-plugin:0.0.1-1")), | ||||||
|  | 			}, | ||||||
|  | 		} | ||||||
|  | 		got := VerifyDependencies(basePlugins) | ||||||
|  | 		assert.Nil(got) | ||||||
|  | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue