1package v2 2 3import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7) 8 9func TestFixtureCreatesValidAsset(t *testing.T) { 10 assert := assert.New(t) 11 a := FixtureAsset("one") 12 assert.Equal("one", a.Name) 13 assert.NoError(a.Validate()) 14} 15 16func TestValidator(t *testing.T) { 17 assert := assert.New(t) 18 asset := FixtureAsset("one") 19 20 // Given valid asset it should pass 21 assert.NoError(asset.Validate()) 22 23 // Given asset without a name it should not pass 24 asset = FixtureAsset("") 25 assert.Error(asset.Validate()) 26 27 // Given asset without a URL it should not pass 28 asset = FixtureAsset("name") 29 asset.URL = "" 30 assert.Error(asset.Validate()) 31 32 // Given asset without an namespace it should not pass 33 asset = FixtureAsset("name") 34 asset.Namespace = "" 35 assert.Error(asset.Validate()) 36 37 // Given asset with an invalid URL it should not pass 38 asset = FixtureAsset("name") 39 asset.URL = "asdfasdf" 40 assert.Error(asset.Validate()) 41 42 // Given asset with a non-HTTP URL it should not pass 43 asset = FixtureAsset("name") 44 asset.URL = "file:///root/my_script.sh" 45 assert.Error(asset.Validate()) 46 47 // Given asset with valid filters 48 asset = FixtureAsset("name") 49 asset.Filters = []string{`entity.OS in ("macos", "linux")`} 50 assert.NoError(asset.Validate()) 51 52 // Given asset without a Sha512 it should not pass 53 asset = FixtureAsset("name") 54 asset.Sha512 = "" 55 assert.Error(asset.Validate()) 56 57 // Given asset with an invalid Sha512 it should not pass 58 asset = FixtureAsset("name") 59 asset.Sha512 = "nope" 60 assert.Error(asset.Validate()) 61} 62