-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
135 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package fanbox_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/hareku/fanbox-dl/pkg/fanbox" | ||
) | ||
|
||
func stringPointer(str string) *string { | ||
return &str | ||
} | ||
|
||
func TestPostBody_OrderedImageMap(t *testing.T) { | ||
type fields struct { | ||
Blocks *[]fanbox.Block | ||
Images *[]fanbox.Image | ||
ImageMap *map[string]fanbox.Image | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
fields fields | ||
want []fanbox.Image | ||
}{ | ||
{ | ||
name: "sort images by blocks order", | ||
fields: fields{ | ||
Images: nil, | ||
Blocks: &[]fanbox.Block{ | ||
{ | ||
Type: "image", | ||
ImageID: stringPointer("first"), | ||
}, | ||
{ | ||
Type: "image", | ||
ImageID: stringPointer("second"), | ||
}, | ||
}, | ||
ImageMap: &map[string]fanbox.Image{ | ||
"second": { | ||
ID: "second_image", | ||
}, | ||
"first": { | ||
ID: "first_image", | ||
}, | ||
}, | ||
}, | ||
want: []fanbox.Image{ | ||
{ | ||
ID: "first_image", | ||
}, | ||
{ | ||
ID: "second_image", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "return nil if Blocks and ImageMap are nil", | ||
fields: fields{ | ||
Images: &[]fanbox.Image{}, | ||
Blocks: nil, | ||
ImageMap: nil, | ||
}, | ||
want: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
b := &fanbox.PostBody{ | ||
Blocks: tt.fields.Blocks, | ||
Images: tt.fields.Images, | ||
ImageMap: tt.fields.ImageMap, | ||
} | ||
if got := b.OrderedImageMap(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("PostBody.OrderedImageMap() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.