syft/imgbom/protocol_test.go
Alfredo Deza 3eedb86a1f tests for protocol.go
Signed-off-by: Alfredo Deza <adeza@anchore.com>
2020-07-02 16:09:55 -04:00

44 lines
921 B
Go

package imgbom
import "testing"
func TestNewProtocol(t *testing.T) {
testCases := []struct {
desc string
input string
expType ProtocolType
expValue string
}{
{
desc: "directory protocol",
input: "dir:///opt/",
expType: DirProtocol,
expValue: "/opt/",
},
{
desc: "unknown protocol",
input: "s4:///opt/",
expType: ImageProtocol,
expValue: "s4:///opt/",
},
{
desc: "docker protocol",
input: "docker://ubuntu:20.04",
expType: ImageProtocol,
expValue: "docker://ubuntu:20.04",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
p := NewProtocol(test.input)
if p.Type != test.expType {
t.Errorf("mismatched type in protocol: '%v' != '%v'", p.Type, test.expType)
}
if p.Value != test.expValue {
t.Errorf("mismatched protocol value: '%s' != '%s'", p.Value, test.expValue)
}
})
}
}