1// Copyright (C) 2019 Storj Labs, Inc. 2// See LICENSE for copying information. 3 4package trust_test 5 6import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 12 "storj.io/storj/storagenode/trust" 13) 14 15func TestNewSource(t *testing.T) { 16 for _, tt := range []struct { 17 name string 18 config string 19 typ interface{} 20 err string 21 }{ 22 { 23 name: "unrecognized schema", 24 config: "ftp://domain.test", 25 err: `unsupported schema "ftp"`, 26 }, 27 { 28 name: "HTTP source (using http)", 29 config: "http://domain.test", 30 typ: new(trust.HTTPSource), 31 }, 32 { 33 name: "HTTP source (using https)", 34 config: "https://domain.test", 35 typ: new(trust.HTTPSource), 36 }, 37 { 38 name: "relative file path", 39 config: "path.txt", 40 typ: new(trust.FileSource), 41 }, 42 { 43 name: "posix absolute file path", 44 config: "/some/path.txt", 45 typ: new(trust.FileSource), 46 }, 47 { 48 name: "windows absolute file path", 49 config: "C:\\some\\path.txt", 50 typ: new(trust.FileSource), 51 }, 52 { 53 name: "windows file path", 54 config: "C:\\some\\path.txt", 55 typ: new(trust.FileSource), 56 }, 57 { 58 name: "explicit satellite URL", 59 config: "storj://121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@domain.test:7777", 60 typ: new(trust.StaticURLSource), 61 }, 62 { 63 name: "explicit bad satellite URL", 64 config: "storj://domain.test:7777", 65 err: "static source: invalid satellite URL: must contain an ID", 66 }, 67 { 68 name: "satellite URL", 69 config: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@domain.test:7777", 70 typ: new(trust.StaticURLSource), 71 }, 72 { 73 name: "partial satellite URL", 74 config: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@", 75 err: "static source: invalid satellite URL: must specify the host:port", 76 }, 77 { 78 name: "partial satellite URL", 79 config: "domain.test:7777", 80 err: "static source: invalid satellite URL: must contain an ID", 81 }, 82 } { 83 tt := tt // quiet linting 84 t.Run(tt.name, func(t *testing.T) { 85 source, err := trust.NewSource(tt.config) 86 if tt.err != "" { 87 require.EqualError(t, err, tt.err) 88 return 89 } 90 require.NoError(t, err) 91 assert.IsType(t, tt.typ, source) 92 }) 93 } 94} 95