(t *testing.T)
| 101 | } |
| 102 | |
| 103 | func TestGetMetadataFields(t *testing.T) { |
| 104 | tests := []struct { |
| 105 | name string |
| 106 | subject string |
| 107 | expected []string |
| 108 | withError error |
| 109 | }{ |
| 110 | { |
| 111 | name: "parse v2 tokens", |
| 112 | subject: "$JS.ACK.domain.hash-123.stream.cons.100.200.150.123456789.100.token", |
| 113 | expected: []string{"$JS", "ACK", "domain", "hash-123", "stream", "cons", "100", "200", "150", "123456789", "100", "token"}, |
| 114 | }, |
| 115 | { |
| 116 | name: "parse v2 tokens with underscore domain", |
| 117 | subject: "$JS.ACK._.hash-123.stream.cons.100.200.150.123456789.100.token", |
| 118 | expected: []string{"$JS", "ACK", "", "hash-123", "stream", "cons", "100", "200", "150", "123456789", "100", "token"}, |
| 119 | }, |
| 120 | { |
| 121 | name: "parse v1 tokens", |
| 122 | subject: "$JS.ACK.stream.cons.100.200.150.123456789.100", |
| 123 | expected: []string{"$JS", "ACK", "", "", "stream", "cons", "100", "200", "150", "123456789", "100"}, |
| 124 | }, |
| 125 | { |
| 126 | name: "invalid start of subject", |
| 127 | subject: "$ABC.123.stream.cons.100.200.150.123456789.100", |
| 128 | withError: ErrInvalidSubjectFormat, |
| 129 | }, |
| 130 | { |
| 131 | name: "invalid subject length (10)", |
| 132 | subject: "$JS.ACK.stream.cons.100.200.150.123456789.100.ABC", |
| 133 | withError: ErrInvalidSubjectFormat, |
| 134 | }, |
| 135 | { |
| 136 | name: "invalid subject length (5)", |
| 137 | subject: "$JS.ACK.stream.cons.100", |
| 138 | withError: ErrInvalidSubjectFormat, |
| 139 | }, |
| 140 | { |
| 141 | name: "invalid subject ", |
| 142 | subject: "", |
| 143 | withError: ErrInvalidSubjectFormat, |
| 144 | }, |
| 145 | } |
| 146 | |
| 147 | for _, test := range tests { |
| 148 | t.Run(test.name, func(t *testing.T) { |
| 149 | res, err := GetMetadataFields(test.subject) |
| 150 | if test.withError != nil { |
| 151 | if err == nil || !errors.Is(err, test.withError) { |
| 152 | t.Fatalf("Expected error: %v; got: %v", test.withError, err) |
| 153 | } |
| 154 | return |
| 155 | } |
| 156 | if !reflect.DeepEqual(test.expected, res) { |
| 157 | t.Fatalf("Invalid result; want: %v; got: %v", test.expected, res) |
| 158 | } |
| 159 | }) |
| 160 | } |
nothing calls this directly
no test coverage detected