diff --git a/imgbom/protocol_test.go b/imgbom/protocol_test.go new file mode 100644 index 000000000..c76f07db8 --- /dev/null +++ b/imgbom/protocol_test.go @@ -0,0 +1,43 @@ +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) + } + + }) + } +}