(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestRepositoryContent_GetContent(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | tests := []struct { |
| 22 | encoding, content *string // input encoding and content |
| 23 | want string // desired output |
| 24 | wantErr bool // whether an error is expected |
| 25 | }{ |
| 26 | { |
| 27 | encoding: Ptr(""), |
| 28 | content: Ptr("hello"), |
| 29 | want: "hello", |
| 30 | wantErr: false, |
| 31 | }, |
| 32 | { |
| 33 | encoding: nil, |
| 34 | content: Ptr("hello"), |
| 35 | want: "hello", |
| 36 | wantErr: false, |
| 37 | }, |
| 38 | { |
| 39 | encoding: nil, |
| 40 | content: nil, |
| 41 | want: "", |
| 42 | wantErr: false, |
| 43 | }, |
| 44 | { |
| 45 | encoding: Ptr("base64"), |
| 46 | content: Ptr("aGVsbG8="), |
| 47 | want: "hello", |
| 48 | wantErr: false, |
| 49 | }, |
| 50 | { |
| 51 | encoding: Ptr("bad"), |
| 52 | content: Ptr("aGVsbG8="), |
| 53 | want: "", |
| 54 | wantErr: true, |
| 55 | }, |
| 56 | { |
| 57 | encoding: Ptr("none"), |
| 58 | content: nil, |
| 59 | want: "", |
| 60 | wantErr: true, |
| 61 | }, |
| 62 | } |
| 63 | |
| 64 | for _, tt := range tests { |
| 65 | r := RepositoryContent{Encoding: tt.encoding, Content: tt.content} |
| 66 | got, err := r.GetContent() |
| 67 | if err != nil && !tt.wantErr { |
| 68 | t.Errorf("RepositoryContent(%v, %v) returned unexpected error: %v", |
| 69 | stringOrNil(tt.encoding), stringOrNil(tt.content), err) |
| 70 | } |
| 71 | if err == nil && tt.wantErr { |
| 72 | t.Errorf("RepositoryContent(%v, %v) did not return unexpected error", |
| 73 | stringOrNil(tt.encoding), stringOrNil(tt.content)) |
| 74 | } |
| 75 | if want := tt.want; got != want { |
| 76 | t.Errorf("RepositoryContent.GetContent returned %+v, want %+v", got, want) |
nothing calls this directly
no test coverage detected
searching dependent graphs…